#include<cstdio> int sum(long long n){ int k = 0; while(n > 0){ k += (n % 10) * (n % 10); n /= 10; } return k; } int main(){ long long a, b, k, result = 0; scanf("%lld %lld %lld", &k, &a, &b); for(long long i = (a % k == 0 ? a : a + k - (a % k)); i <= b && i <= (k < 1e15 ? 1458 * k : 1e18); i += k) if(i/k == sum(i)) result++; printf("%lld", 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> int sum(long long n){ int k = 0; while(n > 0){ k += (n % 10) * (n % 10); n /= 10; } return k; } int main(){ long long a, b, k, result = 0; scanf("%lld %lld %lld", &k, &a, &b); for(long long i = (a % k == 0 ? a : a + k - (a % k)); i <= b && i <= (k < 1e15 ? 1458 * k : 1e18); i += k) if(i/k == sum(i)) result++; printf("%lld", result); return 0; } |