Guest User

Untitled

a guest
Jan 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. /*
  2. MIPT, task # 006
  3. "Three Squares"
  4. 12.09.2011
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <math.h>
  9.  
  10. #define SQR(a) ((a) * (a))
  11.  
  12. int main ()
  13. {
  14. int n, i;
  15. scanf ("%d", &n);
  16.  
  17. int ans = 0;
  18. while (n >= 0) {
  19. char found = 0;
  20. int a, b, c;
  21. for (a = 0; SQR (a) <= n && !found; ++a) {
  22. for (b = 0; SQR (a) + SQR (b) <= n && !found; ++b) {
  23. c = n - SQR (a) - SQR(b);
  24. float sqrt_c = sqrt(c);
  25. if (sqrt_c == (int)(sqrt_c)) {
  26. found = 1;
  27. //printf ("%d + %d + %d = %d\n", SQR (a), SQR (b), SQR (c), n);
  28. }
  29. }
  30. }
  31.  
  32. if (!found) {
  33. ++ans;
  34. }
  35.  
  36. --n;
  37. }
  38.  
  39.  
  40.  
  41. printf ("%d", ans);
  42.  
  43. return 0;
  44. }
Add Comment
Please, Sign In to add comment