// row.cpp : Defines the entry point for the console application.
//
#include "stdio.h"
long long a, b, k, n, x, x1, x2, x3;
int w;
long long fn(long long n)
{
long long f;
long long r;
f = 0;
while (n>0)
{
r = n % 10;
n /= 10;
f += r * r;
}
return f;
}
int main()
{
scanf("%lld %lld%lld", &k, &a, &b);
x1 = (a + k - 1) / k;
x2 = b / k;
n = b;
x3 = 0;
while (n>0)
{
if (n>=10)
x3 += 9 * 9;
else
x3 += n * n;
n /= 10;
}
if (x2>x3)
x2 = x3;
x = x1;
n = k * x1;
while (x<=x2)
{
if (fn(n) == x)
w++;
n += k;
x++;
}
printf("%d\n", w);
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | // row.cpp : Defines the entry point for the console application. // #include "stdio.h" long long a, b, k, n, x, x1, x2, x3; int w; long long fn(long long n) { long long f; long long r; f = 0; while (n>0) { r = n % 10; n /= 10; f += r * r; } return f; } int main() { scanf("%lld %lld%lld", &k, &a, &b); x1 = (a + k - 1) / k; x2 = b / k; n = b; x3 = 0; while (n>0) { if (n>=10) x3 += 9 * 9; else x3 += n * n; n /= 10; } if (x2>x3) x2 = x3; x = x1; n = k * x1; while (x<=x2) { if (fn(n) == x) w++; n += k; x++; } printf("%d\n", w); return 0; } |
English