#include <iostream> #include <math.h> using namespace std; unsigned int sumOfSquares(unsigned int n) { unsigned int sum = 0; while (n>0) { int digit = n%10; sum += digit*digit; n /= 10; } return sum; } int main() { unsigned int k, a, b; cin >> k >> a >> b; a = ceil((double)a/k)*k; unsigned int result = 0; for (unsigned int i = a; i <= b; i += k) if (sumOfSquares(i)*k == i) result++; cout << result << endl; 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 | #include <iostream> #include <math.h> using namespace std; unsigned int sumOfSquares(unsigned int n) { unsigned int sum = 0; while (n>0) { int digit = n%10; sum += digit*digit; n /= 10; } return sum; } int main() { unsigned int k, a, b; cin >> k >> a >> b; a = ceil((double)a/k)*k; unsigned int result = 0; for (unsigned int i = a; i <= b; i += k) if (sumOfSquares(i)*k == i) result++; cout << result << endl; return 0; } |