project euler problem 12
来源:互联网 发布:局域网斗地主软件 编辑:程序博客网 时间:2024/05/17 01:30
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?
此题刚开始不敢尝试,因为做过了,超时了,等了好久,还没出来结果。所以做到了第16题,又做了POJ的一些题目,然后对记忆化递归了解了才写了这道题。
#include <iostream>#include <map>#include <string>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>using namespace std;int cmp(int n){ if(n==1) return 1; int sum=cmp(n-1)+n; //直接记住结果,就不会超时了。 return sum;}int abc(int n){ int i,sum=0; for(i=1;i<=sqrt(n*1.0);i++) if(n%i==0) sum++; //虽然用了sqrt,但是还是超过了1秒,这个用不了记忆化,所以时间还是有点多。 return sum;}int main(){ int i; for(i=1000;;i++) if(abc(cmp(i))>=250) {cout<<cmp(i)<<endl;break;} //因为sqrt之前的就知道了总共的因子了,乘以2就是其因子数。 return 0;}
- Project Euler problem 12
- project euler problem 12
- Project Euler – Problem 12
- Euler Project Problem 6
- project euler problem 11
- Project Euler Problem 81
- Project Euler Problem 60
- Project Euler Problem 59
- Project Euler Problem 58
- Project Euler Problem 57
- Project Euler Problem 16
- Project Euler Problem 30
- Project Euler Problem 31
- Project Euler Problem 32
- Project Euler Problem 14
- Project Euler Problem 15
- Project Euler Problem 17
- Project Euler - Problem 18
- C专家编程--指针与数组(二) 数组 指针 联系
- JS之浏览器对象含义
- 【五子棋AI】AI的基本结构——招法生成器
- 【leetcode】Binary Tree Inorder Traversal
- liunx 下配置mysql的问题
- project euler problem 12
- C专家编程--指针和数组(三) 值传递 指针传递 引用传递
- JS之函数定义的三种方式
- for 循环执行顺序
- shell简单练习
- 查看、修改oracle字符集,查看oracle版本
- log4j配置说明
- C专家编程--指针和数组(四) 指针对数组的访问
- 会话跟踪技术