// Michal Zagorski // Rownanie #include <cstdio> typedef unsigned long long ull; ull fun(ull arg, ull digits[10]){ ull result = 0; while(arg > 0){ result += digits[arg%10]; arg /= 10; } return result; } int main(){ ull k = 0, a = 0, b = 0; scanf("%llu %llu %llu", &k, &a, &b); ull digits[10] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81}; ull counter = 0; for(ull i = a; i <= b ; i++){ if(k * fun(i, digits) == i) counter++; } printf("%llu", counter); 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 | // Michal Zagorski // Rownanie #include <cstdio> typedef unsigned long long ull; ull fun(ull arg, ull digits[10]){ ull result = 0; while(arg > 0){ result += digits[arg%10]; arg /= 10; } return result; } int main(){ ull k = 0, a = 0, b = 0; scanf("%llu %llu %llu", &k, &a, &b); ull digits[10] = {0, 1, 4, 9, 16, 25, 36, 49, 64, 81}; ull counter = 0; for(ull i = a; i <= b ; i++){ if(k * fun(i, digits) == i) counter++; } printf("%llu", counter); return 0; } |