#include <cstdio> bool check(long long num, int sum) { while (num) { int d = num%10; sum -= d*d; num /= 10; } return sum == 0; } int main() { long long k, a, b; scanf("%lld%lld%lld", &k, &a, &b); long long i = (a+k-1)/k; int c = 0; for (long long num = i*k; num < b && i < 2000; ++i, num += k) { if (check(num, i)) { ++c; } } printf("%d\n", c); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <cstdio> bool check(long long num, int sum) { while (num) { int d = num%10; sum -= d*d; num /= 10; } return sum == 0; } int main() { long long k, a, b; scanf("%lld%lld%lld", &k, &a, &b); long long i = (a+k-1)/k; int c = 0; for (long long num = i*k; num < b && i < 2000; ++i, num += k) { if (check(num, i)) { ++c; } } printf("%d\n", c); } |