fork(3) download
  1. #include <stdio.h>
  2.  
  3. int isWeird(int* s, int a, int b, int k, int n){
  4. int i,t,r;
  5. printf("%d\n",k);
  6. if(k==n) return 0;
  7. else if(k<n) return -1;
  8. for(i=a;(t=k-s[i])>=n;i++){
  9. r=isWeird(s,i+1,b,t,n);
  10. if(r==0) return r;
  11. }
  12. return -1;
  13. }
  14.  
  15. int main(void) {
  16. int c, n, s[1000],b,i,k;
  17. scanf("%d",&c);
  18. s[0]=1;
  19. while(c--){
  20. scanf("%d",&n);
  21. b=k=1;
  22. for(i=2;i*i<=n;i++){
  23. if(n%i==0) s[b++]=i;
  24. }
  25. for(i=b-1;i>0;i--){
  26. k+=s[i];
  27. s[b]=n/s[i];
  28. if(s[b]!=s[i]) k+=s[b++];
  29. }
  30. if(k>n){
  31. if(isWeird(s,0,b,k,n)) printf("weird\n");
  32. else printf("not weird\n");
  33. } else {
  34. printf("not weird\n");
  35. }
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0s 2252KB
stdin
3
6
12
70
stdout
not weird
16
15
13
12
not weird
74
73
71
72
weird