#include<iostream>
#include<map>
using namespace std;
#define mx 1458
#define ull unsigned long long
ull suma(ull x)
{
ull s=0;
while(x>0LL)
{
s+=(x%10)*(x%10);
x/=10LL;
}
// cout<<s;
return s;
}
int main()
{
unsigned long long k, a, b, pom;
cin>>k>>a>>b;
int ile = 0;
map <ull,int> mapa;
for(unsigned long long i=1;i<=mx;i++)
{
pom = k*suma(i*k);
// cout<<pom<<endl;
if(pom>=a&&pom<=b&&suma(i*k)==suma(pom))
{
mapa[pom]++;
if(mapa[pom]==1)
++ile;
}
}
cout<<ile;
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<iostream> #include<map> using namespace std; #define mx 1458 #define ull unsigned long long ull suma(ull x) { ull s=0; while(x>0LL) { s+=(x%10)*(x%10); x/=10LL; } // cout<<s; return s; } int main() { unsigned long long k, a, b, pom; cin>>k>>a>>b; int ile = 0; map <ull,int> mapa; for(unsigned long long i=1;i<=mx;i++) { pom = k*suma(i*k); // cout<<pom<<endl; if(pom>=a&&pom<=b&&suma(i*k)==suma(pom)) { mapa[pom]++; if(mapa[pom]==1) ++ile; } } cout<<ile; return 0; } |
English