// Potyczki1.cpp : Defines the entry point for the console application. // #include <stdio.h> #include <climits> int sum_of_digits(long long in) { int res = 0; for( ; in > 0; in /= 10) { int digit = in % 10; res += digit * digit; } return res; } int main() { long long k, a, b; scanf("%lld %lld %lld", &k, &a, &b); int res = 0; long long max_possible_sum_square = LLONG_MAX / k; if (max_possible_sum_square > 20 * 9 * 9) { max_possible_sum_square = 20 * 9 * 9; } for ( int sum_square = 1; sum_square <= max_possible_sum_square; sum_square++) { long long n = k * sum_square; if (n >= a && n <= b) { if (sum_of_digits(n) == sum_square) { 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 40 41 42 43 44 | // Potyczki1.cpp : Defines the entry point for the console application. // #include <stdio.h> #include <climits> int sum_of_digits(long long in) { int res = 0; for( ; in > 0; in /= 10) { int digit = in % 10; res += digit * digit; } return res; } int main() { long long k, a, b; scanf("%lld %lld %lld", &k, &a, &b); int res = 0; long long max_possible_sum_square = LLONG_MAX / k; if (max_possible_sum_square > 20 * 9 * 9) { max_possible_sum_square = 20 * 9 * 9; } for ( int sum_square = 1; sum_square <= max_possible_sum_square; sum_square++) { long long n = k * sum_square; if (n >= a && n <= b) { if (sum_of_digits(n) == sum_square) { res++; } } } printf("%d\n", res); return 0; } |