#include <bits/stdc++.h> using namespace std; int Funct(long long int n) { int res = 0; while(n != 0) { int ld = n % 10; n /= 10; res += ld * ld; } return res; } int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); long long int k, a, b; cin >> k >> a >> b; int upper = 81 * 22; int res = 0; for (int i = 0; i < upper; ++i) { long long int n = k * (long long int)i; if (n / k != i) break; if (a <= n && b >= n && Funct(n) == i) { res++; //cerr << n << endl; } } 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 | #include <bits/stdc++.h> using namespace std; int Funct(long long int n) { int res = 0; while(n != 0) { int ld = n % 10; n /= 10; res += ld * ld; } return res; } int main(int argc, char const *argv[]) { ios::sync_with_stdio(false); long long int k, a, b; cin >> k >> a >> b; int upper = 81 * 22; int res = 0; for (int i = 0; i < upper; ++i) { long long int n = k * (long long int)i; if (n / k != i) break; if (a <= n && b >= n && Funct(n) == i) { res++; //cerr << n << endl; } } cout << res << endl; return 0; } |