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
| #include <iostream> #include <cmath>
using namespace std;
bool isPerfectSquare(int n) { int attemp = (int)sqrt(n); return attemp * attemp == n; } bool isRight(int n) { if (!isPerfectSquare(n)) { return false; } for (int i = 1; i <= 6; i++) { int tmp = (int)pow(10.0, (double)i); if (tmp >= n) { break; } if (n % tmp != 0) { int right = n % tmp; int left = (n - right) / tmp; if (isPerfectSquare(left) && isPerfectSquare(right)) { return true; } } } return false; }
int a, b;
int main(int argc, char const *argv[]) { cin >> a >> b; for (int i = a; i <= b; i++) { if (isRight(i)) { cout << i << '\n'; } }
return 0; }
|