Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4. #include <map>
  5. #include <set>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <utility>
  9.  
  10.  
  11. using namespace std;
  12.  
  13. bool checkLen(int a) {
  14. string s = to_string(a);
  15. return (s.size() % 2 == 0);
  16. }
  17.  
  18. bool checkDiv(int i, int a) {
  19. string f = to_string(a);
  20. string s = to_string(i);
  21. string d = to_string(a / i);
  22. return (s.size() == f.size() / 2 && d.size() == f.size() / 2);
  23. }
  24.  
  25. bool anagr(int a, int i) {
  26. string s = to_string(a);
  27. string d = to_string(i + a / i);
  28. sort(s.begin(), s.end());
  29. sort(d.begin(), d.end());
  30. return s == d;
  31. }
  32.  
  33. bool solve(int a) {
  34. if (checkLen(a) && a != 0) {
  35. for (int i = 1; i * i <= a; i++) {
  36. if (a % i == 0) {
  37. if (checkDiv(i, a)) {
  38. if (i % 2 != 0 || (a / i) % 2 != 0) {
  39. if (anagr(a, i)) {
  40. return 1;
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }
  47. return 0;
  48. }
  49.  
  50.  
  51. int main() {
  52. int n, a;
  53. cin >> n;
  54. for (int i = 0; i < n; i++) {
  55. cin >> a;
  56. if (solve(a)) cout << "YES" << endl;
  57. else cout << "NO" << endl;
  58. }
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement