#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <ctime> using namespace std; int f(long long x) { int res = 0; while (x) { res += (x % 10)*(x % 10); x /= 10; } return res; } int main() { long long a, b, k; cin >> k >> a >> b; long long ans = 0; for (long long sum = 0; sum <= 2000; sum++) { long long cand = k*sum; if (cand > 1000000000000000000LL) { break; } if (f(cand) == sum && cand >= a && cand <= b) { // cout << cand << endl; ans++; } } cout << ans << endl; 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 37 38 39 40 41 42 43 44 45 46 47 | #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <vector> #include <map> #include <set> #include <ctime> using namespace std; int f(long long x) { int res = 0; while (x) { res += (x % 10)*(x % 10); x /= 10; } return res; } int main() { long long a, b, k; cin >> k >> a >> b; long long ans = 0; for (long long sum = 0; sum <= 2000; sum++) { long long cand = k*sum; if (cand > 1000000000000000000LL) { break; } if (f(cand) == sum && cand >= a && cand <= b) { // cout << cand << endl; ans++; } } cout << ans << endl; return 0; } |