#include <iostream>
#define ULL unsigned long long
using namespace std;
inline ULL power(ULL num)
{
ULL res = 0;
ULL tmp;
while (num)
{
tmp = num % 10;
num /= 10;
res += tmp*tmp;
}
return res;
}
int main()
{
ULL a, b, k;
ios::sync_with_stdio(false);
cin >> k >> a >> b;
if (a < k)
a = k;
else
a -= (a % k) - k;
ULL counter = 0;
for (ULL i = a; i <= b; i += k)
{
if (power(i) == i / k)
++counter;
}
cout << counter;
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 | #include <iostream> #define ULL unsigned long long using namespace std; inline ULL power(ULL num) { ULL res = 0; ULL tmp; while (num) { tmp = num % 10; num /= 10; res += tmp*tmp; } return res; } int main() { ULL a, b, k; ios::sync_with_stdio(false); cin >> k >> a >> b; if (a < k) a = k; else a -= (a % k) - k; ULL counter = 0; for (ULL i = a; i <= b; i += k) { if (power(i) == i / k) ++counter; } cout << counter; return 0; } |
English