#include <iostream> #include<cstdio> #include<algorithm> #include<vector> #include<queue> using namespace std; #define LL unsigned long long #define F first #define S second #define MP make_pair #define PB push_back vector<LL> V; LL res=0; LL fun(LL x) { LL r=0; LL i=1; while((x/i)>0) { r+=((x/i)%10)*((x/i)%10); i*=10; } return r; } int main() { LL k, a, b; scanf("%lld%lld%lld", &k, &a, &b); for(LL i=1; i<=1500; i++) { if(i*k>b) break; if(i*k>=a) V.PB(i*k); } for(int i=0; i<(int)V.size(); i++) { if(fun(V[i])*k==V[i]) res++; } printf("%lld\n", res); 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 | #include <iostream> #include<cstdio> #include<algorithm> #include<vector> #include<queue> using namespace std; #define LL unsigned long long #define F first #define S second #define MP make_pair #define PB push_back vector<LL> V; LL res=0; LL fun(LL x) { LL r=0; LL i=1; while((x/i)>0) { r+=((x/i)%10)*((x/i)%10); i*=10; } return r; } int main() { LL k, a, b; scanf("%lld%lld%lld", &k, &a, &b); for(LL i=1; i<=1500; i++) { if(i*k>b) break; if(i*k>=a) V.PB(i*k); } for(int i=0; i<(int)V.size(); i++) { if(fun(V[i])*k==V[i]) res++; } printf("%lld\n", res); return 0; } |