Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <string>
- #include <map>
- #include <set>
- #include <vector>
- #include <algorithm>
- #include <utility>
- using namespace std;
- bool checkLen(int a) {
- string s = to_string(a);
- return (s.size() % 2 == 0);
- }
- bool checkDiv(int i, int a) {
- string f = to_string(a);
- string s = to_string(i);
- string d = to_string(a / i);
- return (s.size() == f.size() / 2 && d.size() == f.size() / 2);
- }
- bool anagr(int a, int i) {
- string s = to_string(a);
- string d = to_string(i + a / i);
- sort(s.begin(), s.end());
- sort(d.begin(), d.end());
- return s == d;
- }
- bool solve(int a) {
- if (checkLen(a) && a != 0) {
- for (int i = 1; i * i <= a; i++) {
- if (a % i == 0) {
- if (checkDiv(i, a)) {
- if (i % 2 != 0 || (a / i) % 2 != 0) {
- if (anagr(a, i)) {
- return 1;
- }
- }
- }
- }
- }
- }
- return 0;
- }
- int main() {
- int n, a;
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> a;
- if (solve(a)) cout << "YES" << endl;
- else cout << "NO" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement