#include<algorithm> #include<iostream> #include<vector> #define int long long using namespace std; vector<bool> C(1459, false); void wypelnij() { for(int i=1; i<10; i++) C[i*i]=true; for(int i=0; i<17; i++) for(int j=C.size()-1; j>-1; j--) if(C[j]) for(int k=1; k<10; k++) C[j+k*k]=true; } int f(int a) { int resu=0; while(a>0) { resu+=(a%10)*(a%10); a/=10; } return resu; } main() { ios_base::sync_with_stdio(false); wypelnij(); int k, a, b; cin>>k>>a>>b; int resu=0; for(int i=1; i<C.size(); i++) if(C[i] && a<=k*i && k*i<=b && f(k*i)==i) resu++; cout<<resu<<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 | #include<algorithm> #include<iostream> #include<vector> #define int long long using namespace std; vector<bool> C(1459, false); void wypelnij() { for(int i=1; i<10; i++) C[i*i]=true; for(int i=0; i<17; i++) for(int j=C.size()-1; j>-1; j--) if(C[j]) for(int k=1; k<10; k++) C[j+k*k]=true; } int f(int a) { int resu=0; while(a>0) { resu+=(a%10)*(a%10); a/=10; } return resu; } main() { ios_base::sync_with_stdio(false); wypelnij(); int k, a, b; cin>>k>>a>>b; int resu=0; for(int i=1; i<C.size(); i++) if(C[i] && a<=k*i && k*i<=b && f(k*i)==i) resu++; cout<<resu<<endl; return 0; } |