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)的更多相关文章

  1. 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 ...

  2. Project Euler problem 63

    这题略水啊 首先观察一下. 10 ^ x次方肯定是x + 1位的 所以底数肯定小于10的 那么我们就枚举1~9为底数 然后枚举幂级数就行了,直至不满足题目中的条件即可break cnt = 0 for ...

  3. Project Euler problem 68

    题意须要注意的一点就是, 序列是从外层最小的那个位置顺时针转一圈得来的.而且要求10在内圈 所以,这题暴力的话,假定最上面那个点一定是第一个点,算下和更新下即可. #include <iostr ...

  4. Project Euler problem 62

    题目的大意很简单 做法的话. 我们就枚举1~10000的数的立方, 然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的. 然后就可以用map来搞了 ...

  5. Project Euler problem 61

    题意很明了. 然后我大概的做法就是暴搜了 先把每个几边形数中四位数的处理出来. 然后我就DFS回溯着找就行了. 比较简单吧. #include <cstdio> #include < ...

  6. Project Euler Problem 675

    ORZ foreverlasting聚聚,QQ上问了他好久才会了这题(所以我们又聊了好久的Gal) 我们先来尝试推导一下\(S\)的性质,我们利用狄利克雷卷积来推: \[2^\omega=I\ast| ...

  7. Project Euler Problem 26-Reciprocal cycles

    看样子,51nod 1035 最长的循环节 这道题应该是从pe搬过去的. 详解见论文的(二)那部分:http://web.math.sinica.edu.tw/math_media/d253/2531 ...

  8. Project Euler Problem 24-Lexicographic permutations

    全排列的生成,c++的next_permutation是O(n)生成全排列的.具体的O(n)生成全排列的算法,在 布鲁迪 的那本组合数学中有讲解(课本之外,我就看过这一本组合数学),冯速老师翻译的,具 ...

  9. Project Euler Problem 23-Non-abundant sums

    直接暴力搞就行,优化的地方应该还是计算因子和那里,优化方法在这里:http://www.cnblogs.com/guoyongheng/p/7780345.html 这题真坑,能被写成两个相同盈数之和 ...

随机推荐

  1. EntityFramework进阶(一)- DbContext与ObjectContext互转

    本系列原创博客代码已在EntityFramework6.0.0测试通过,转载请标明出处 EF中我们常用的是DbContext作为上下文,如果要想获取元数据等信息还是要用到ObjectContext这个 ...

  2. ubuntu无法安装usb驱动

    第一步: 输入命令 lsusb 箭头指向的就是连接的手机 第二步: 输入命令,新建并打开文件 sudo gedit /etc/udev/rules.d/-android.rules [注意]如果提示没 ...

  3. Android驱动之设备树简介

    目录 一.    设备树简介    2 1.    问题一:为什么需要设备树?    2 ①名词解释:    2 ②DT详细介绍:    2 ③DTS是DT的源文件,描述Device Tree中的设备 ...

  4. 第二篇:Python基本知识

    这一篇我们简单的介绍一下Python学习的基本知识-->Python文件是如何运行.Python文件打开通常会有两行注释,那么这两行注释是什么:上篇提到的字节码,这些字节码都存储在哪?即pyc文 ...

  5. tcpdump命令及输出详解

    一. 使用方法 1. 指定类型 host:指定主机 tcpdump host 192.168.100.1 tcpdump host 192.168.100.1 and !192.168.100.2 t ...

  6. ubuntu 修改环境变量(PATH)

    1.什么是环境变量(PATH) 在Linux中,在执行命令时,系统会按照PATH的设置,去每个PATH定义的路径下搜索执行文件,先搜索到的文件先执行. 我们知道查阅文件属性的指令ls 完整文件名为:/ ...

  7. Warning | 3719 | 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous.

    MySQL的“utf8”实际上不是真正的UTF-8.“utf8”只支持每个字符最多三个字节,而真正的UTF-8是每个字符最多四个字节. MySQL一直没有修复这个bug,他们在2010年发布了一个叫作 ...

  8. shell中判断前一个命令是否执行成功

    ]; then echo "fail" else echo "success" fi 或者 ]; then echo "success" e ...

  9. 运输层4——TCP可靠运输的工作原理

    目录 1. 停止等待协议 写在前面:本文章是针对<计算机网络第七版>的学习笔记 运输层1--运输层协议概述 运输层2--用户数据报协议UDP 运输层3--传输控制协议TCP概述 运输层4- ...

  10. Robot Framework--用例、数据、流程分离例子

    如果想改变输入框的输入词,则需要不停的复制case,为了减少冗余,可以做一个简单的分层,把搜索流程剥离成一个关键字,然后再不同的case中调用这个关键字,然后传递不同的参数,以进行不同数据在同一流程下 ...