#include <iostream> #include <algorithm> using namespace std; long long int a, b, k, s, i, wyn; int main() { ios_base::sync_with_stdio(0); cin >> k >> a >> b; wyn = 0; i = a; if (i%k != 0) i = i + k - (i % k); while ((i <= b) && (i <= k*81*18)) { s = 0; int j = i; while (j > 0) { s = (j%10) * (j%10) + s; j = j / 10; }; if (k * s == i) wyn++; i = i + k; } cout << wyn; 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 32 33 34 35 36 | #include <iostream> #include <algorithm> using namespace std; long long int a, b, k, s, i, wyn; int main() { ios_base::sync_with_stdio(0); cin >> k >> a >> b; wyn = 0; i = a; if (i%k != 0) i = i + k - (i % k); while ((i <= b) && (i <= k*81*18)) { s = 0; int j = i; while (j > 0) { s = (j%10) * (j%10) + s; j = j / 10; }; if (k * s == i) wyn++; i = i + k; } cout << wyn; return 0; } |