#include <iostream>
using namespace std;
unsigned int k = 0;
unsigned int a = 0;
unsigned int b = 0;
int squares[]
{
0, 1, 4, 9, 16, 25, 36, 49, 64, 72
};
int main()
{
cin >> k >> a >> b;
//k = 51;
//k = 51;
//a = 1;
//b = 1000000000000; //12
long long int result = 0;
for (unsigned int n = a; n <= b; n++)
{
unsigned int n_tmp = n;
unsigned int f_result = 0;
while (n_tmp != 0)
{
f_result += squares[(n_tmp % 10)];
n_tmp = n_tmp / 10;
}
if (f_result*k == n) result++;
}
cout << result;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <iostream> using namespace std; unsigned int k = 0; unsigned int a = 0; unsigned int b = 0; int squares[] { 0, 1, 4, 9, 16, 25, 36, 49, 64, 72 }; int main() { cin >> k >> a >> b; //k = 51; //k = 51; //a = 1; //b = 1000000000000; //12 long long int result = 0; for (unsigned int n = a; n <= b; n++) { unsigned int n_tmp = n; unsigned int f_result = 0; while (n_tmp != 0) { f_result += squares[(n_tmp % 10)]; n_tmp = n_tmp / 10; } if (f_result*k == n) result++; } cout << result; return 0; } |
English