#include <iostream> #define int long long using namespace std; struct ran { int p, q; ran(int p, int q) { this->p = p; this->q = q; }; }; int f(int n) { int res = 0, d; while (n > 0) { d = n % 10; res += d*d; n /= 10; } return res; }; main() { ios_base::sync_with_stdio(0); int a, b, k; cin >> k >> a >> b; ran fr = ran(1, 81 * 18); ran gr = ran(a / k, (b / k) + 1); ran kr = ran(max(fr.p, gr.p), min(fr.q, gr.q)); int res = 0; for (int i = kr.p; i <= kr.q; i++) { int x = i * k; if (f(x) == i) res++; } cout << res << 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 | #include <iostream> #define int long long using namespace std; struct ran { int p, q; ran(int p, int q) { this->p = p; this->q = q; }; }; int f(int n) { int res = 0, d; while (n > 0) { d = n % 10; res += d*d; n /= 10; } return res; }; main() { ios_base::sync_with_stdio(0); int a, b, k; cin >> k >> a >> b; ran fr = ran(1, 81 * 18); ran gr = ran(a / k, (b / k) + 1); ran kr = ran(max(fr.p, gr.p), min(fr.q, gr.q)); int res = 0; for (int i = kr.p; i <= kr.q; i++) { int x = i * k; if (f(x) == i) res++; } cout << res << endl; return 0; } |