#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <list> #include <climits> #include <string> #include <stack> #include <map> #include <set> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <sstream> #include <iomanip> #include <cassert> #define ALL(v) v.begin(), v.end() #define REP(i, a, b) for(int i = a; i < b; i++) #define REPD(i, a, b) for(int i = a; i > b; i--) #define REPLL(i, a, b) for(ll i = a; i < b; i++) #define FOR(i, a, b) for(int i = a; i <= b; i++) #define FORD(i, a, b) for(int i = a; i >= b; i--) #define FORLL(i, a, b) for(ll i = a; i <= b; i++) #define inf 1000000001 using namespace std; typedef long long ll; typedef long double ld; typedef vector<int>::iterator vit; typedef set<int>::iterator sit; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii > vpii; typedef pair<ld, ld> pld; #define remax(a, b) a = max(a, b) #define remin(a, b) a = min(a, b) #define popcount __builtin_popcount #define pb push_back #define mp make_pair #define st first #define nd second #define eps 1e-9 #define pi acos(-1.0) #define maxn 1389 ll z, n, k, a, b; ll f(ll n) { stringstream ss; int ret = 0; string s; ss << n; ss >> s; REP(i, 0, s.size()) { ret += (s[i] - '0') * (s[i] - '0'); } return ret; } int main() { ios_base::sync_with_stdio(0); cin >> k >> a >> b; int ret = 0; FOR(x, 1, 1500) { ll n = k * x; if (n >= a && n <= b && k * f(n) == n) { ret++; } } cout << ret << endl; }
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <list> #include <climits> #include <string> #include <stack> #include <map> #include <set> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <sstream> #include <iomanip> #include <cassert> #define ALL(v) v.begin(), v.end() #define REP(i, a, b) for(int i = a; i < b; i++) #define REPD(i, a, b) for(int i = a; i > b; i--) #define REPLL(i, a, b) for(ll i = a; i < b; i++) #define FOR(i, a, b) for(int i = a; i <= b; i++) #define FORD(i, a, b) for(int i = a; i >= b; i--) #define FORLL(i, a, b) for(ll i = a; i <= b; i++) #define inf 1000000001 using namespace std; typedef long long ll; typedef long double ld; typedef vector<int>::iterator vit; typedef set<int>::iterator sit; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii > vpii; typedef pair<ld, ld> pld; #define remax(a, b) a = max(a, b) #define remin(a, b) a = min(a, b) #define popcount __builtin_popcount #define pb push_back #define mp make_pair #define st first #define nd second #define eps 1e-9 #define pi acos(-1.0) #define maxn 1389 ll z, n, k, a, b; ll f(ll n) { stringstream ss; int ret = 0; string s; ss << n; ss >> s; REP(i, 0, s.size()) { ret += (s[i] - '0') * (s[i] - '0'); } return ret; } int main() { ios_base::sync_with_stdio(0); cin >> k >> a >> b; int ret = 0; FOR(x, 1, 1500) { ll n = k * x; if (n >= a && n <= b && k * f(n) == n) { ret++; } } cout << ret << endl; } |