Advertisement
GeeckoDev

pe142

Nov 4th, 2012
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int isPerfect(int n)
  5. {
  6.     int h = n & 0xF;
  7.    
  8.     if (h <= 9)
  9.     {
  10.         if (h != 2 && h != 3 && h != 5 && h != 6 && h != 7 && h != 8)
  11.         {
  12.             int t = sqrtf(n);
  13.             return t*t == n;
  14.         }
  15.     }
  16.    
  17.     return 0;
  18. }
  19.  
  20. int main()
  21. {
  22.     int x, y, z;
  23.    
  24.     for (x=3;; x++)
  25.     {
  26.         for (y=2; y<x; y++)
  27.         {
  28.             if (!isPerfect(x+y) || !isPerfect(x-y))
  29.                 continue;
  30.            
  31.             for (z=1; z<y; z++)
  32.             {
  33.                 if (isPerfect(x+z) && isPerfect(x-z) &&
  34.                     isPerfect(y+z) && isPerfect(y-z))
  35.                 {
  36.                     printf("%d\n", x+y+z);
  37.                     return 0;
  38.                 }
  39.             }
  40.         }
  41.     }
  42.    
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement