fork download
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <stdbool.h>
  4. #define ll long long
  5.  
  6. ll t, n;
  7.  
  8. ll summ(ll x) {
  9. ll s = 0;
  10. while (x > 0) {
  11. s += x % 10;
  12. x /= 10;
  13. }
  14. return s;
  15. }
  16.  
  17. ll doo(ll x) {
  18. ll s = 0;
  19. for (ll i = 2; i * i <= x; i++) {
  20. while(x % i == 0) {
  21. x /= i;
  22. s += summ(i);
  23. }
  24. }
  25. if (x > 1) s += summ(x);
  26. return s;
  27. }
  28.  
  29.  
  30. int main() {
  31.  
  32. scanf("%lld", &t);
  33. while (t--) {
  34. scanf("%lld", &n);
  35. if (doo(n) == summ(n)) printf("1");
  36. else printf("0");
  37. printf("\n");
  38.  
  39. }
  40.  
  41. return 0;
  42. }
Success #stdin #stdout 0s 5320KB
stdin
2
2
387
stdout
1
0