#include <cstdio> long long f(long long n) { long long ret = 0; while (n != 0) { long long v = n % 10; ret += v * v; n /= 10; } return ret; } int main() { long long k, a, b; scanf("%lld%lld%lld", &k, &a, &b); long long result = 0; for (long long i = a + k - a % k; i <= b; i += k) { if (i / k == f(i)) result++; } printf("%lld\n", 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 | #include <cstdio> long long f(long long n) { long long ret = 0; while (n != 0) { long long v = n % 10; ret += v * v; n /= 10; } return ret; } int main() { long long k, a, b; scanf("%lld%lld%lld", &k, &a, &b); long long result = 0; for (long long i = a + k - a % k; i <= b; i += k) { if (i / k == f(i)) result++; } printf("%lld\n", result); return 0; } |