Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int n;
  7. cin >> n;
  8. for(int i=0;i<n;i++){
  9. int num;
  10. cin >> num;
  11. bool ok = false;
  12. for(int d = 1; d * d <= num; d++){
  13. if(num % d) continue;
  14. int a=d, b=num/d;
  15. multiset<int> l, r;
  16. int c = a;
  17. while(c){
  18. l.insert(c%10);
  19. c/=10;
  20. }
  21. c = b;
  22. while(c){
  23. r.insert(c%10);
  24. c/=10;
  25. }
  26. if(a%10 == 0 && b%10==0) continue;
  27. multiset<int> res;
  28. for(int aa: l) res.insert(aa);
  29. for(int bb: r) res.insert(bb);
  30. if(!(l.size() == res.size()/2 && r.size() == res.size()/2)){
  31. continue;
  32. }
  33. c = num;
  34. while(c){
  35. if(res.find(c%10) == res.end()){
  36. res.insert(-1);
  37. break;
  38. }
  39. res.erase(res.find(c%10));
  40. c/=10;
  41. }
  42. if(res.size() == 0){
  43. ok = true;
  44. break;
  45. }
  46. }
  47. if(ok){
  48. cout << "YES" << endl;
  49. }
  50. else{
  51. cout << "NO" << endl;
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement