//============================================================================ // Name : PA2015.cpp // Author : Kornel // Description : Row //============================================================================ #include <stdio.h> using namespace std; #define MAX 1458 int f(long long n) { int res = 0LL; int lastDigit = 0; while (n >= 1) { lastDigit = n % 10; n /= 10; res += lastDigit * lastDigit; } return res; } int main() { long long k; long long a; long long b; scanf("%lld %lld %lld", &k, &a, &b); int res = 0; int max = MAX < b/k ? MAX : b/k; for (int fn = 0; fn <= max; fn++) { long long candidateN = k * fn; if ((k * f(candidateN) == candidateN) && (candidateN >= a && candidateN <= b)) { res++; } } printf("%d\n", res); 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 | //============================================================================ // Name : PA2015.cpp // Author : Kornel // Description : Row //============================================================================ #include <stdio.h> using namespace std; #define MAX 1458 int f(long long n) { int res = 0LL; int lastDigit = 0; while (n >= 1) { lastDigit = n % 10; n /= 10; res += lastDigit * lastDigit; } return res; } int main() { long long k; long long a; long long b; scanf("%lld %lld %lld", &k, &a, &b); int res = 0; int max = MAX < b/k ? MAX : b/k; for (int fn = 0; fn <= max; fn++) { long long candidateN = k * fn; if ((k * f(candidateN) == candidateN) && (candidateN >= a && candidateN <= b)) { res++; } } printf("%d\n", res); return 0; } |