目录
Problem1 3或5的倍数
-原题(翻译来自pe-cn.github.io 下同)
英语原题
中文翻译
Multiples of 3 and 5
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9.The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
3或5的倍数
在小于10的自然数中,3或5的倍数有3、5、6和9,这些数之和是23。
求小于1000的自然数中所有3或5的倍数之和。
-思路
没啥好说的 就是穷举
-代码
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int sum=0;//统计总和
for(int i=1;i<1000;i++)//枚举1到1000 看看每个数是否符合要求
{
if(i%3==0||i%5==0) sum+=i;//如果符合 总和加上当前数
}
cout<<sum;//输出
}
-答案
233168
Problem2 偶斐波那契数
-原题
英语原题
中文翻译
Even Fibonacci numbers
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ···
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
偶斐波那契数
在小于10的自然数中,3或5的倍数有3、5、6和9,这些数之和是23。
斐波那契数列中的每一项都是前两项的和。由和开始生成的斐波那契数列的前项为:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ···
考虑该斐波那契数列中不超过四百万的项,求其中为偶数的项之和。
-思路
把从1到4000000之间的斐波那契数列每一项算出来 然后把其中的偶数累加
-代码
#include<cstdio>
#include<iostream>
using namespace std;
int a[100086

本文详细介绍了Project Euler的前五个问题,包括3或5的倍数之和、偶斐波那契数之和、最大质因数、最大回文乘积和最小公倍数的解决方案。使用c++编程语言,通过穷举、斐波那契数列和质因数分解等方法求解,并给出了每个问题的答案。
最低0.47元/天 解锁文章
513





