题目12:第一个拥有超过500个约数的三角形数是多少?
projecteuler吧
全部回复
仅看楼主
level 6
arll_1 楼主
第一个拥有超过500个约数的三角形数是多少?三角形数序列是由对自然数的连加构造而成的。所以第七个三角形数是1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. 那么三角形数序列中的前十个是:
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...下面我们列出前七个三角形数的约数: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可以看出28是第一个拥有超过5个约数的三角形数。那么第一个拥有超过500个约数的三角形数是多少?
2012年06月05日 08点06分 1
level 10
这个你的算法程序多少秒???
2012年06月05日 15点06分 2
level 6
arll_1 楼主
#define ORIGIN 500
void main (void)
{
__int64 i = 0;
clock_t start=0,finish=0;
double duration;
int sum = 0;
int j = 0;
__int64 aim_num = 0;
start = clock();
for(i=1;sum<ORIGIN;i++)
{
sum = 0;
aim_num += i;
for(j=1;j*j<aim_num;j++)
{
if (0 == aim_num%j)
{
sum+=2;
}
}
if (j*j == aim_num)
{
sum++;
}
if (ORIGIN == sum)
{
printf("%d\n",aim_num);
break;
}
}
printf("%d\n",aim_num);
finish= clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf("%f\n",duration);
printf("%d\n",i);
}
1.45300s

2012年06月06日 11点06分 3
ORIGIN == sum?你这个算法真有验证过?
2012年08月25日 05点08分
level 6
arll_1 楼主
后面的题目每天争取做出来一题吧,呵呵
2012年06月06日 12点06分 4
level 6
arll_1 楼主
#include<iostream>#
include#includeusing namespace std;int a[2000]={0},b[100]={0},c[100]={0};int main(){int n=1,i,j,m,l=0,ind=0;int f1,f2;while(1){m=n+1;ind=0;l=n*(n+1)/2;f1=0;f2=0;for(i=1;i<=sqrt(m);i++){if(m%i==0){b[f1++]=i;b[f1++]=m/i;}}for(i=1;i<=sqrt(n);i++){if(n%i==0){c[f2++]=i;c[f2++]=n/i;}}if(f1*f2>=500){for(j=0;j=500) break;}n++;}cout<
2012年06月06日 14点06分 5
level 10
没看懂什么意思。。。
以后帖代码最好截图一下吧。。。
2012年06月06日 15点06分 6
level 6
arll_1 楼主
就是那句关键语句就是这种算法的方法,不过这种算法有误差,所以他用了很多数组来纠错。
2012年06月07日 01点06分 7
level 6
arll_1 楼主
#include<iostream>#
include#include
using namespace std;int a[2000]={0},b[100]={0},c[100]={0};

2012年06月07日 01点06分 8
level 10
运行结果
76576500 time: 829ms
2012年06月10日 04点06分 10
level 2
受楼上启发。算法用共轭因数优化。
若num=a*b,则称a,b互为共轭因数==
2012年08月09日 12点08分 11
对对,就是这个意思。。。
2012年08月10日 03点08分
level 8
不明觉厉!
2012年08月10日 10点08分 12
level 1
我用python写的,算了8秒[拍砖]
2012年08月19日 04点08分 13
level 6
OCaml,0.3秒
2012年08月19日 07点08分 14
[啊!][啊!]C++还0.8s呢。。。。
2012年08月20日 02点08分
回复 xw_y_am :呵呵,膜拜我吧~其实是用了OCaml编译器的速度优化的
2012年08月20日 03点08分
这个还是用算法去优化吧,上面不是有一个算法 0.094s,当然不同机器计算的时间也会不一样,编译器也会有影响,还是从算法复杂度和时间复杂度来解决运算速度的问题吧。
2012年08月21日 11点08分
level 3
因式分解然后,弄一下就可以了~~
2012年08月24日 11点08分 15
恩,速度是原来的5倍多。
2012年08月25日 06点08分
level 6
其实只要找到前250个并且250个小于251个,旧OK了
2012年12月09日 05点12分 16
1