#include<iostream> #include<algorithm> #define int long long using namespace std; int check(int x) { int res=0; while(x>0) { int mod=x%10; res+=(mod*mod); x/=10; } return res; } main() { ios_base::sync_with_stdio(0); int k, a, b, res=0; cin >> k >> a >> b; if(k>b) { cout << 0 << endl; return 0; } int left=a/k; int right=b/k; left=max(left, 1LL); right=min(right, 81LL*18LL); for(int i=left; i<=right; ++i) { if(i==check(k*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 | #include<iostream> #include<algorithm> #define int long long using namespace std; int check(int x) { int res=0; while(x>0) { int mod=x%10; res+=(mod*mod); x/=10; } return res; } main() { ios_base::sync_with_stdio(0); int k, a, b, res=0; cin >> k >> a >> b; if(k>b) { cout << 0 << endl; return 0; } int left=a/k; int right=b/k; left=max(left, 1LL); right=min(right, 81LL*18LL); for(int i=left; i<=right; ++i) { if(i==check(k*i)) res++; } cout << res << endl; return 0; } |