Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <windows.h>
- typedef unsigned long DWORD;
- int calculate(long n)
- {
- double square = sqrt(n);
- int isquare = (int)floor(square);
- int count = isquare == square ? -1 : 0;
- long candidate;
- for (candidate = 1; candidate <= isquare; candidate ++)
- if (0 == n % candidate) count += 2;
- return count;
- }
- int main ()
- {
- DWORD mark = GetTickCount();
- long triangle = 1;
- int index = 1;
- while (calculate(triangle) < 1001)
- {
- index++;
- triangle += index;
- }
- printf("%ld\n", triangle);
- DWORD end = GetTickCount();
- printf("%d\n", (end-mark)); //ms
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement