Summation of primes
是我算法不对,还是笔记本CPU太差?
我优化了两次,还是花了三四个小时来得到结果。
在输出上加1就是最终结果。
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
def isprime(n):
boolisprime = True
for i in xrange(3,n):
if n % i == 0:
boolisprime = False
break
return boolisprime
def primenumber(n):
i = 1
sumprime = 0
while True:
if isprime(i) == True:
sumprime += i
print i,sumprime
if i > n:
break
i += 2
return sumprime
print primenumber(2000000)+1
Note: This problem has been changed recently, please check that you are using the right parameters.
-->
Summation of primes的更多相关文章
- projecteuler Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two milli ...
- (Problem 10)Summation of primes
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two milli ...
- Problem 10: Summation of primes
def primeslist(max): ''' 求max值以内的质数序列 ''' a = [True]*(max+1) a[0],a[1]=False,False for index in rang ...
- PE 001~010
题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的 ...
- 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 ...
- PE刷题记
PE 中文翻译 最喜欢做这种很有意思的数学题了虽然数学很垃圾 但是这个网站的提交方式好鬼畜啊qwq 1.Multiples of 3 and 5 直接枚举 2.Even Fibonacci numbe ...
- Python练习题 038:Project Euler 010:两百万以内所有素数之和
本题来自 Project Euler 第10题:https://projecteuler.net/problem=10 # Project Euler: Problem 10: Summation o ...
- Summation of Four Primes - PC110705
欢迎访问我的新博客:http://www.milkcu.com/blog/ 原文地址:http://www.milkcu.com/blog/archives/uva10168.html 原创:Summ ...
- UVA 10168 Summation of Four Primes(数论)
Summation of Four Primes Input: standard input Output: standard output Time Limit: 4 seconds Euler p ...
随机推荐
- MySQL行列转换
分类: Mysql/postgreSQL 在某些数据库中有交叉表,但在MySQL中却没有这个功能,但网上看到有不少朋友想找出一个解决方法,特发贴集思广义.http://topic.csdn.net/u ...
- jsonp突破同源策略,实现跨域访问请求
跨域访问问题,相信大家都有遇到过.这是一个很棘手的问题.不过道高一尺,魔高一丈,对于这类问题,总有解决问题的方案.最近我又接触到了这个问题,解决的途径是ajax+jsonp. 说到这个问题,不得不说一 ...
- HDU H204 阿牛的EOF牛肉串
阿牛的EOF牛肉串 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- VB.NET 数组的定义 动态使用 多维数组
我们都知道在全部程序设计语言中数组都是一个非常重要的概念,数组的作用是同意程序猿用同一个名称来引用多个变量,因此採用数组索引来区分这些变量.非常多情况下利用数组索引来设置一个循环,这样就能够高效地处理 ...
- [转] vim 正则表达式 很强大
毋庸多言,在vim中正则表达式得到了十分广泛的应用. 最常用的 / 和 :s 命令中,正则表达式都是不可或缺的. 下面对vim中的正则表达式的一些难点进行说明. 关于magic vim中有个magic ...
- Spark HA 的搭建
接hadoop HA的搭建,因为你zookeeper已经部署完成,所以直接安装spark就可以 tar –xzf spark-1.6.1-bin-hadoop2.6.tgz -C ../service ...
- FastReport 动态修改连接字符串
代码如下: Report rp = new Report(); rp.Load(@"Print\aa.frx"); rp.Dictionary.Connections[0].Con ...
- 简单水池&&迷宫问题
#include <iostream> #include <stdio.h> #include <cstring> using namespace std; int ...
- html图像入门
在HTML中,图像由<img>标签定义. <img>是空标签,意思是说,它只包含属性,并且没有闭合标签. 要在页面上显示图像,需要使用源属性src, src指的是"s ...
- sharepoint查询超出阈值
昨天客户出了webpart显示数据不稳定的bug,经过这两天的艰苦排查终于发现了是列表视图阈值造成的问题,经过在网上搜索终于找到了类似的解决方法. SPQuery query = new SPQuer ...