#include <iostream> #include <cmath> using namespace std; int f (long long int n) { int res = 0; while (n >= 10) { res += (n%10)*(n%10); n /= 10; } res += (n%10)*(n%10); return res; } int cyfry (long long int n) { int res = 0; while (n >= 10) { res++; n/= 10; } res++; return res; } int main () { long long int k,a,b; cin >> k >> a >> b; long long int res = 0; long long int pierw; if (a%k == 0) pierw = a; else pierw = a - (a%k) + k; for (long long int i = pierw; i <=b; i += k) { if (k * cyfry (i) * 81 < pow (10.0 , cyfry(i)-1)) { break; } if (f(i) * k == i) { res++; } } cout<<res<<endl; cin.get(),cin.get(); 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 | #include <iostream> #include <cmath> using namespace std; int f (long long int n) { int res = 0; while (n >= 10) { res += (n%10)*(n%10); n /= 10; } res += (n%10)*(n%10); return res; } int cyfry (long long int n) { int res = 0; while (n >= 10) { res++; n/= 10; } res++; return res; } int main () { long long int k,a,b; cin >> k >> a >> b; long long int res = 0; long long int pierw; if (a%k == 0) pierw = a; else pierw = a - (a%k) + k; for (long long int i = pierw; i <=b; i += k) { if (k * cyfry (i) * 81 < pow (10.0 , cyfry(i)-1)) { break; } if (f(i) * k == i) { res++; } } cout<<res<<endl; cin.get(),cin.get(); return 0; } |