fork(1) download
  1. #include<stdio.h>
  2. #include<math.h>
  3.  
  4. int is_triangular(unsigned long int n)
  5. {
  6. // k**2 + k - 2n = 0
  7. // D = sqrt(1 + 8n)
  8. // k = (-1 + D) / 2
  9.  
  10. double D = sqrt(1 + 8 * n);
  11. if(D - floor(D) == 0)
  12. if( ((unsigned long)D) % 2 == 1)
  13. return 1;
  14. return 0;
  15. }
  16.  
  17. int main()
  18. {
  19. unsigned long int n;
  20. scanf("%lu", &n);
  21.  
  22. if(n == 1)
  23. {
  24. printf("NO");
  25. return 0;
  26. }
  27.  
  28. unsigned long int i;
  29. for(i=1; (i * (i+1) / 2) <= (n/2) ; ++i)
  30. {
  31. unsigned long int triangular = i * (i+1) / 2;
  32. if(is_triangular(n-triangular))
  33. {
  34. printf("YES");
  35. return 0;
  36. }
  37. }
  38. printf("NO");
  39. return 0;
  40. }
Success #stdin #stdout 0s 4316KB
stdin
816761542
stdout
YES