A special site for solving fun programming problems and challenges, interested in computer science, programming, basics, data structure and algorithms

 codeforces: problem Some Sums soultion in c++.


U. Some Sums
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output



Given three numbers N, A, B. Print the summation of the numbers between 1 and N whose sum of digits is between A and B inclusive.

Input

Only one line containing three numbers N, A, B (1 ≤ N ≤ 104, 1 ≤ A ≤ B ≤ 36).

Output

Print a single line contains the answer according to the required above.

Examples

InputOutput
20 2 584
10 1 213

soultion:


#include <iostream>
using namespace std;
int main()
{
int N,A,B,i=1;
int sum=0,s=0;
cin>>N>>A>>B;
while(i<=N)
{
sum=0;
int x=i;
while(x!=0)
{
sum=sum+(x%10);
x/=10;
}
if(sum<=B&&sum>=A)
{
s+=i;
}
i++;
}
cout<<s<<endl;
return 0;
}

No comments:

Post a Comment