#include <iostream> #include <sstream> using namespace std; long long power [10] = { 0, 1, 4, 9, 16, 25,36,49,64,81 }; int match=0; long long funkcjaN(long long digit); int main() { long long k,a,b; cin>>k; cin>>a; cin>>b; for (long long i=a;i<=b;i++) { long long wynik = k*funkcjaN(i); //cout << wynik << endl; if(wynik==i) { match+=1; } } cout << match << endl; return 0; } long long funkcjaN(long long digit) { long long sum = 0; std::ostringstream ss; ss << digit; std::string stringDigit = ss.str(); for(int i=0;i< stringDigit.length();i++) { int index = stringDigit[i]-'0'; sum += power[index]; } return sum; }
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 | #include <iostream> #include <sstream> using namespace std; long long power [10] = { 0, 1, 4, 9, 16, 25,36,49,64,81 }; int match=0; long long funkcjaN(long long digit); int main() { long long k,a,b; cin>>k; cin>>a; cin>>b; for (long long i=a;i<=b;i++) { long long wynik = k*funkcjaN(i); //cout << wynik << endl; if(wynik==i) { match+=1; } } cout << match << endl; return 0; } long long funkcjaN(long long digit) { long long sum = 0; std::ostringstream ss; ss << digit; std::string stringDigit = ss.str(); for(int i=0;i< stringDigit.length();i++) { int index = stringDigit[i]-'0'; sum += power[index]; } return sum; } |