#include <iostream> #include <vector> #include <set> using namespace std; long long f(long long n) { long long sqrtSum = 0; while(n > 0) { int digit = n % 10; sqrtSum += digit * digit; n /= 10; } return sqrtSum; } const long long MAX_SUM = 1458; //9 * 9 * 18 int main() { ios_base::sync_with_stdio(false); long long k, a, b; cin >> k >> a >> b; int count = 0; for(long long i = 0; i <= MAX_SUM; ++i) { unsigned long long n = i * k; if(n > b) break; if(n < a) continue; if(f(n) * k == n) count++; } cout << count << endl; 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 | #include <iostream> #include <vector> #include <set> using namespace std; long long f(long long n) { long long sqrtSum = 0; while(n > 0) { int digit = n % 10; sqrtSum += digit * digit; n /= 10; } return sqrtSum; } const long long MAX_SUM = 1458; //9 * 9 * 18 int main() { ios_base::sync_with_stdio(false); long long k, a, b; cin >> k >> a >> b; int count = 0; for(long long i = 0; i <= MAX_SUM; ++i) { unsigned long long n = i * k; if(n > b) break; if(n < a) continue; if(f(n) * k == n) count++; } cout << count << endl; return 0; } |