#include <iostream> unsigned long long suma(unsigned long long a); int main() { using std::cin; using std::cout; unsigned long long k,a,b; cin >> k; cin >> a; cin >> b; unsigned long long ile = 0; for (unsigned long long n = (a%k==0 ? a : a+k-(a%k)); n <= b; n += k) { if (k*suma(n) == n) ile++; } cout << ile; return 0; } unsigned long long suma(unsigned long long a) { unsigned long long sum = 0; while (a > 0) { sum += (a%10)*(a%10); a /= 10; } return sum; }
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 32 33 34 35 36 37 38 | #include <iostream> unsigned long long suma(unsigned long long a); int main() { using std::cin; using std::cout; unsigned long long k,a,b; cin >> k; cin >> a; cin >> b; unsigned long long ile = 0; for (unsigned long long n = (a%k==0 ? a : a+k-(a%k)); n <= b; n += k) { if (k*suma(n) == n) ile++; } cout << ile; return 0; } unsigned long long suma(unsigned long long a) { unsigned long long sum = 0; while (a > 0) { sum += (a%10)*(a%10); a /= 10; } return sum; } |