#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <vector> using namespace std; #define FNL 1 #define FNH 1500 int f( long long int n ) { int result = 0; while( n>0 ) { result += (n%10)*(n%10); n/=10; } return result; } int main() { ios_base::sync_with_stdio(false); long long int k, a, b; cin >> k >> a >> b; int counter=0; for( int fn = FNL ; fn <= FNH ; fn++ ) { long long int n = k * fn; if( f(n) == fn && a<=n && n<=b ) counter++; } cout << counter << 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 <cstdio> #include <iostream> #include <algorithm> #include <string> #include <vector> using namespace std; #define FNL 1 #define FNH 1500 int f( long long int n ) { int result = 0; while( n>0 ) { result += (n%10)*(n%10); n/=10; } return result; } int main() { ios_base::sync_with_stdio(false); long long int k, a, b; cin >> k >> a >> b; int counter=0; for( int fn = FNL ; fn <= FNH ; fn++ ) { long long int n = k * fn; if( f(n) == fn && a<=n && n<=b ) counter++; } cout << counter << endl; return 0; } |