1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include <stdio.h>
#include <math.h>
int main() {
    long long k, a, b;
    scanf("%lld%lld%lld", &k,&a,&b);
    int result = 0;
    for (int i=0; i<=9*9*18; i++) {
        if (a <= k*i && k*i <= b) {
            long long candidate = k*i;
            int squaresSum = 0;
            do { squaresSum += pow(candidate%10, 2); } while (candidate/=10);
            if (squaresSum == i) result++;
        }
    }
    printf("%lld\n", result);
    return 0;
}