fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define MAXN 10007
  4.  
  5. int a[MAXN];
  6.  
  7. void snt(){
  8. for(int i = 0; i < MAXN; i++){
  9. a[i] = 1;
  10. }
  11. a[0] = a[1] = 0;
  12. for (int i = 2; i < sqrt(MAXN); i++){
  13. if(a[i]){
  14. for(int j = i * i; j < MAXN; j += i){
  15. a[j] = 0;
  16. }
  17. }
  18. }
  19. }
  20.  
  21. int sumnum(long long x){
  22. int s = 0;
  23. while (x > 0){
  24. s += x % 10;
  25. x /= 10;
  26. }
  27. return s;
  28. }
  29.  
  30. int geck(long long n){
  31. if (n < 2) return 0;
  32. long long m = n;
  33. int sum = 0, sntlaplai = 0;
  34. for (int i = 2; (long long)i * i <= m; i++){
  35. if (a[i]){
  36. while (m % i == 0){
  37. sum += sumnum(i);
  38. sntlaplai++;
  39. m /= i;
  40. }
  41. }
  42. }
  43. if (m > 1){
  44. sum += sumnum(m);
  45. sntlaplai++;
  46. }
  47. if (sntlaplai == 1) return 0;
  48. if (sum == sumnum(n)) return 1;
  49. else return 0;
  50. }
  51.  
  52. int main(){
  53. snt();
  54. int t;
  55. scanf("%d", &t);
  56. while (t--){
  57. long long n;
  58. scanf("%lld", &n);
  59. printf("%d\n", geck(n));
  60. }
  61. return 0;
  62. }
Success #stdin #stdout 0s 5320KB
stdin
2
378
730
stdout
1
0