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 这题真坑,能被写成两个相同盈数之和 ...
随机推荐
- hashmap,hashtable,concurrenthashmap多线程下的比较(持续更新)
1.hashMap 多线程下put会造成死循环,主要是扩容时transfer方法会造成死循环. http://blog.csdn.net/zhuqiuhui/article/details/51849 ...
- IO五种模型和select与epoll工作原理(引入nginx)
用户速度体验的1-3-10原则 性能影响 有很多研究都表明,性能对用户的行为有很大的影响: 79%的用户表示不太可能再次打开一个缓慢的网站 47%的用户期望网页能在2秒钟以内加载 40%的用户 ...
- charles 右键菜单
本文参考:charles 右键菜单 在网址/域名上右键 可以获得下面菜单 区域 1 基本操作 :基本的URL复制,文件保存,以及选中文件内搜索 区域 2 重写操作 :重写发送请求(调用接口合适),或者 ...
- Scala配置环境变量windows
scala下载官网网址:http://www.scala-lang.org/download/ 1.下载scala-2.10.4.msi 2.点击安装scala,默认安装路径 3.配置环境变量 ( ...
- Robot Framework--完整的接口测试用例
*** Settings *** Library Collections Library json Library requests Library RequestsLibrary Library H ...
- flask中使用ajax 处理前端请求,每隔一段时间请求不通的接口,结果展示同一页面
需求: flask中使用ajax 处理前端请求,每隔一段时间请求不通的接口,结果展示同一页面 用到 setTimeout方法,setTimeout(function(){},1000):setTime ...
- postgresql —— 查看索引
查索引 语句: SELECT tablename, indexname, indexdef FROM pg_indexes WHERE tablename = 'user_tbl' ORDER BY ...
- nextjs —— jsx style 学习记录
作用域 全局 <style global jsx>{` .hero { width: 100%; color: #333; } .title { margin: 0; width: 100 ...
- 带有EXE参数的启动
(一).先制作一个带启动参数的EXE文件. 步骤: 1.定义全局私有变量:private string[] s = new string[1]; //这里为了简单起见,只做一个 ...
- redis中对list类型某个元素的查找和删除
我们的信息都是放到redis的缓存中,结构为list,如果知道特定的值的话,通过LREM key count value这样就可以.对于redis的list结构,获取某个位置的值通过 LINDE ...