fork(1) download
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4.  
  5. #define MAX 1000
  6.  
  7. long long tcs(int n)
  8. {
  9. long long Tong = 0;
  10. while (n)
  11. {
  12. Tong += n % 10;
  13. n /= 10;
  14. }
  15. return Tong;
  16. }
  17. int main()
  18. {
  19. int t;
  20. cin >> t;
  21. while(t--)
  22. {
  23. int n;
  24. cin >> n;
  25. bool check[n + 2];
  26. for (int i = 2; i <= n+1; i++) {
  27. check[i] = true;
  28. }
  29. for (int i = 2; i <= n+1; i++) {
  30. if (check[i] == true) {
  31. for (int j = 2 * i; j <= n+1; j += i) {
  32. check[j] = false;
  33. }
  34. }
  35. }
  36. if(check[n]==false){
  37. long long sum=tcs(n),dem=0;
  38. while(n%2==0){
  39. n/=2;
  40. dem+=2;
  41. }
  42. for(int i=3;i*i<=n;i+=2){
  43. while(n%i==0){
  44. n/=i;
  45. dem+=tcs(i);
  46. }
  47. }
  48. if(n>2) dem+=n;
  49. if(dem==sum)
  50. cout << "YES" << endl;
  51. else cout << "NO" << endl;
  52. }
  53. else cout<<"NO"<<endl;
  54. }
  55. return 0;
  56. }
Success #stdin #stdout 0s 4524KB
stdin
3
4
3 
666
stdout
YES
NO
NO