【 Project Euler | 欧拉计划】Problem1~5 c++详解+答案

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

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的自然数中所有35的倍数之和。

-思路

没啥好说的 就是穷举

-代码

#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
评论 9
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值