Advertisement
Guest User

Untitled

a guest
Jul 29th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <windows.h>
  4.  
  5. typedef unsigned long DWORD;
  6.  
  7. int calculate(long n)
  8. {
  9.     double square = sqrt(n);
  10.     int isquare = (int)floor(square);
  11.     int count = isquare == square ? -1 : 0;
  12.     long candidate;
  13.     for (candidate = 1; candidate <= isquare; candidate ++)
  14.         if (0 == n % candidate) count += 2;
  15.     return count;
  16. }
  17.  
  18. int main ()
  19. {
  20.     DWORD mark = GetTickCount();
  21.     long triangle = 1;
  22.     int index = 1;
  23.     while (calculate(triangle) < 1001)
  24.     {
  25.         index++;
  26.         triangle += index;
  27.     }
  28.     printf("%ld\n", triangle);
  29.     DWORD end = GetTickCount();
  30.     printf("%d\n", (end-mark)); //ms
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement