| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

Highly divisible triangular number

Problem 12

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 <iostream>

using namespace std;

int main()
{
int n, i, dvsr;
int c1 = { 0, 0}, c2 = { 0, 0};
long int numb, count, numb1, count1;

const long int N = 1000000;

numb = 0;
count = 0;

for(n = 1;;n ++)
{
c2 =
c2 = 0;

for(i = 1;i <= n;i ++)
{
if(!(n%i))
{
c2 ++;               //stands for the number of devisers
if(i%2)c2 ++;        //stands for odd devisors
}
}

dvsr = c2+c1-1            //the sum of devisors
+c2*c1-3          //the product of devisors
-c2-c1;
numb += n;
if(numb >= N)
{
count += N;
numb -= N;
}

if(dvsr >= 500)break;

c1 = c2;
c1 = c2;
}

numb1 = count1 = 0;                //to check if the numb is correct
for(i = 0;i <= n;i ++)
{
numb1 += i;
if(numb1 > N)
{
numb1 -= N;
count1 ++;
}
}

cout << "Hello world!" << endl
<< n << endl << count << endl << numb << endl << dvsr << endl
<< numb1 << endl << count1 << endl;
return 0;
}         [fly]存在即是合理[/fly]     [fly]存在即是合理[/fly]     [fly]存在即是合理[/fly]        • 6
• 1/1页
• • 1
• 