#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; const ll MAX = 1500; ll f(ll x) { ll sum = 0; while(x) { sum += (x % 10)*(x % 10); x /= 10; } return sum; } int main() { ll a, b, k; scanf("%llu%llu%llu", &k, &a, &b); if(a % k != 0) a += k - (a % k); int S = 0; for( ; a <= b && a/k <= MAX; a += k) if(f(a) == a/k) ++S; printf("%d\n", S); 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 | #include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; const ll MAX = 1500; ll f(ll x) { ll sum = 0; while(x) { sum += (x % 10)*(x % 10); x /= 10; } return sum; } int main() { ll a, b, k; scanf("%llu%llu%llu", &k, &a, &b); if(a % k != 0) a += k - (a % k); int S = 0; for( ; a <= b && a/k <= MAX; a += k) if(f(a) == a/k) ++S; printf("%d\n", S); return 0; } |