#include <iostream> #include <cstdio> int getDigitsSquaredSum(long long int num) { int result = 0; while (num) { result += (num % 10) * (num % 10); num /= 10; } return result; } int main() { long long int k, a, b; scanf("%lld%lld%lld", &k, &a, &b); int result = 0; for (int j = 1; j <= 81 * 18; j++) { if (getDigitsSquaredSum(k * j) == j && a <= k * j && k * j <= b) { result++; } } printf("%d", 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 | #include <iostream> #include <cstdio> int getDigitsSquaredSum(long long int num) { int result = 0; while (num) { result += (num % 10) * (num % 10); num /= 10; } return result; } int main() { long long int k, a, b; scanf("%lld%lld%lld", &k, &a, &b); int result = 0; for (int j = 1; j <= 81 * 18; j++) { if (getDigitsSquaredSum(k * j) == j && a <= k * j && k * j <= b) { result++; } } printf("%d", result); return 0; } |