1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <cstdio>
using namespace std;
typedef long long LL;
LL sq(LL n) { return n*n; }
int f(LL n) { return n ? f(n/10) + sq(n%10) : 0; }
int main() {
LL k, a, b;
scanf("%lld %lld %lld", &k, &a, &b);
int res = 0;
for (LL i=1;i <= 18*81 && k*i <= b;i++)
{
LL n = k*i;
res += n >= a && f(n) == i;
}
printf("%d\n", res);
return 0;
}
|