#include <iostream> #include <stdint.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int64_t k, a, b; int64_t res = 0; cin >> k >> a >> b; while(a <= b) { int64_t t = a; int64_t sum = 0; while(t > 0) { sum += (t%10)*(t%10); t = t/10; } if(sum * k == a) { res++; a += k; } else a++; } cout << res << "\n"; }
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 | #include <iostream> #include <stdint.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int64_t k, a, b; int64_t res = 0; cin >> k >> a >> b; while(a <= b) { int64_t t = a; int64_t sum = 0; while(t > 0) { sum += (t%10)*(t%10); t = t/10; } if(sum * k == a) { res++; a += k; } else a++; } cout << res << "\n"; } |