projecteuler problem 12
2009-05-05 15:17
323 查看
// Triangle.cpp : Defines the entry point for the console application. // /* The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that 28 is the first triangle number to have over five divisors. What is the value of the first triangle number to have over five hundred divisors? */ #include "stdafx.h" #include "windows.h" #include <cmath> #include <iostream> using namespace std; int Divisors(unsigned long num) { int divs = 2; long tmp = sqrt((long double)num); for(int i = 2; i < tmp; i++) { if(num % i == 0) { divs += 2;// double divisors } } if((tmp * tmp) == num) { divs++; } return divs; } int _tmain(int argc, _TCHAR* argv[]) { LARGE_INTEGER EndTime ; LARGE_INTEGER Frequency ; LARGE_INTEGER BegainTime ; QueryPerformanceFrequency(&Frequency); QueryPerformanceCounter(&BegainTime) ; unsigned long t = 3; int divs = 2, i = 3; while(divs <= 500) { t += i; i++; divs = Divisors(t); } cout << t << endl; QueryPerformanceCounter(&EndTime) ; cout << ( EndTime.QuadPart - BegainTime.QuadPart )*1000 / Frequency.QuadPart << endl; system("pause"); return 0; }
相关文章推荐
- Project Euler problem 12
- Project Euler Problem 12: Highly divisible triangular number
- project euler problem 12
- Project Euler -> problem 12
- Project Euler Problem 12
- project euler Problem 39
- Project Euler problem 5
- Project Euler problem 9 勾股数
- Project Euler problem 29
- Project Euler problem 34
- Project Euler problem 39
- Project Euler problem 43
- Project Euler problem 46
- Project Euler Problem 60
- Project Euler Problem 27小结
- Project Euler Problem 31
- project euler Problem 3
- 欧拉,projecteuler Problem 83
- Project Euler Problem 36
- Project Euler Problem 50