Project Euler Problem (1~10)
1.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 100
(计算1000以内能被3或5整除的数之和)
#include <iostream>
using namespace std;
int main()
{
int i;
int sum = 0;
for (i = 1; i <= 1000; i++)
{
if (i % 3 == 0 || i % 5 == 0)
sum = sum + i;
}
cout << sum << endl;
return 0;
}
运行结果:
234168
2.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, ...Find the sum of all the even-valued terms in the sequence which do not exceed one million.
(计算斐波那契数列中小于100万的偶数项之和)
#include <iostream>
using namespace std;
int main()
{
int a = 1, b = 2;
int sum = 0;
while(a < 1000000 && b < 1000000)
{
if (a % 2 == 0)
sum = sum + a;
if (b % 2 == 0)
sum = sum + b;
a = a + b;
b = b + a;
}
cout << sum << endl;
return 0;
}
运行结果:
257114
3.The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 317584931803?
(分解出317584931803的因数)
#include <iostream>
using namespace std;
int main()
{
int i;
long long n = 317584931803;
for (i = 2; i <= n; i++)
{
while (n != i)
{
if (n % i == 0)
{
n = n / i;
}
else
break;
}
} //从2开始将每个数作为n的除数,若整除则为因数后重新计算n再判断
cout << n << endl;//前面只输入前面几个较小因数,重新计算的最后一个n为最大因数
return 0;
}
运行结果:
3919
4.A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.Find the largest palindrome made from the product of two 3-digit numbers.
(找出两个三位数相乘的最大回文数)
Project Euler Problem (1~10)的更多相关文章
- Project Euler Problem 10
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of ...
- Project Euler problem 63
这题略水啊 首先观察一下. 10 ^ x次方肯定是x + 1位的 所以底数肯定小于10的 那么我们就枚举1~9为底数 然后枚举幂级数就行了,直至不满足题目中的条件即可break cnt = 0 for ...
- Project Euler problem 68
题意须要注意的一点就是, 序列是从外层最小的那个位置顺时针转一圈得来的.而且要求10在内圈 所以,这题暴力的话,假定最上面那个点一定是第一个点,算下和更新下即可. #include <iostr ...
- Project Euler problem 62
题目的大意很简单 做法的话. 我们就枚举1~10000的数的立方, 然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的. 然后就可以用map来搞了 ...
- Project Euler problem 61
题意很明了. 然后我大概的做法就是暴搜了 先把每个几边形数中四位数的处理出来. 然后我就DFS回溯着找就行了. 比较简单吧. #include <cstdio> #include < ...
- Project Euler Problem 675
ORZ foreverlasting聚聚,QQ上问了他好久才会了这题(所以我们又聊了好久的Gal) 我们先来尝试推导一下\(S\)的性质,我们利用狄利克雷卷积来推: \[2^\omega=I\ast| ...
- Project Euler Problem 26-Reciprocal cycles
看样子,51nod 1035 最长的循环节 这道题应该是从pe搬过去的. 详解见论文的(二)那部分:http://web.math.sinica.edu.tw/math_media/d253/2531 ...
- Project Euler Problem 24-Lexicographic permutations
全排列的生成,c++的next_permutation是O(n)生成全排列的.具体的O(n)生成全排列的算法,在 布鲁迪 的那本组合数学中有讲解(课本之外,我就看过这一本组合数学),冯速老师翻译的,具 ...
- Project Euler Problem 23-Non-abundant sums
直接暴力搞就行,优化的地方应该还是计算因子和那里,优化方法在这里:http://www.cnblogs.com/guoyongheng/p/7780345.html 这题真坑,能被写成两个相同盈数之和 ...
随机推荐
- FreeRTOS 任务挂起和恢复
在使用RTOS的时候一个实时应用可以作为一个独立的任务.每个任务都有自己的运行环境, 不依赖于系统中其他的任务或者RTOS调度器. 任何一个时间点只能有一个任务运行,具体运行哪个任务是由RTOS调度器 ...
- IDEA提示不区分大小写设置
File–>Settings–>Editor–>General–>Code Completion–>Mach case的勾取消掉就可以了 取消勾后效果如下
- java判定数据(对象)类型
1.说明一 int 是关键字,Integer是包装类,Number是所有数字了的基类(父类).所以,Number是Integer的基础,Integer是int的基础,也称Integer是int的原型类 ...
- csdr Makefile for openwrt(纯粹笔记,暂未成功)
1.自已学着写的Makefile给csdr在openwrt平台上使用 参照:https://blog.csdn.net/lvshaorong/article/details/54668220 incl ...
- yum nginx最新版安装
去官方站点获取yum仓库 [root@web01 ~]# cat /etc/yum.repos.d/nginx.repo [nginx] name=nginx repo baseurl=http:// ...
- jar命令详解
原文链接:https://www.cnblogs.com/anyehome/p/9435371.html JAR包是Java中所特有一种压缩文档,其实大家就可以把它理解为.zip包.当然也是有区别的, ...
- k8s的核心对象
一.Deployment的概念 K8S本身并不提供网络的功能,所以需要借助第三方网络插件进行部署K8S中的网络,以打通各个节点中容器的互通. POD,是K8S中的一个逻辑概念,K8S管理的是POD,一 ...
- centOS7 下 安装mysql8.x
第一部分 CentOS7安装mysql1.1 安装前清理工作:1.1.1 清理原有的mysql数据库:使用以下命令查找出安装的mysql软件包和依赖包: rpm -pa | grep mysql 显示 ...
- 生成器调试---send方式
调试 def creat_num(all_num): a, b = 0, 1 current_num = 0 while current_num < all_num: ret = yield a ...
- celery指定任务执行时间
有业务线提出需求:要求对于其流量,只能在0点到7点扫描. 对此,celery发送任务到队列时可以指定执行的时间. 当worker收到任务后,判断还未到执行时间,会存储在worker中,在到达时候后再执 ...