projecteuler---->problem=10----Summation of primes

title:

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

翻译:

10下面的质数的和为2 + 3 + 5 + 7 = 17。

请求出200,0000下面全部质数的和。

import math,time
def isOk(a):
	for i in range(2,int(math.sqrt(a))+1):
		if a%i==0:
			return False
	return True
s=0
begin=time.time()
for i in range(2,2000000):
	if isOk(i):
		s += i
print s
end = time.time()
print end-begin
时间: 2024-08-28 04:32:37

projecteuler---->problem=10----Summation of primes的相关文章

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

Summation of primes

problem 10:Summation of primes 题意:求不大于200w的素数和 代码如下: 1 #ifndef PRO10_H_INCLUDED 2 #define PRO10_H_INCLUDED 3 4 #include "prime.h" 5 #include <cstring> 6 7 int p[2000000]; 8 bool vis[10000005]; 9 long long solve(){ 10 memset(vis,0,sizeof(vi

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 million. 译文: 10以下的素数之和为17,求出2000000以下的素数之和. ======================= 第一次code: 1 import java.util.Scanner; 2 3 public class Main { 4 public static void main(

leetcode problem 10 Regular Expression Matching

Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be

projecteuler之58题Spiral primes

package com.android; public class SpiralPrimes { public static void main(String args[]) { long numPrimes = 0; long numAll = 0; long oneStart = 1; for (long i = 3; i < Long.MAX_VALUE; i = i + 2) { numAll = 2*i-1; if(isPrimes(i*i)){ numPrimes++; } if(i

Python练习题 038:Project Euler 010:两百万以内所有素数之和

本题来自 Project Euler 第10题:https://projecteuler.net/problem=10 # Project Euler: 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 million. # Answer: 142913828922 def f(x):

uva 10168 Summation of Four Primes(数论-哥德巴赫猜想)

Problem A Summation of Four Primes Input: standard input Output: standard output Time Limit: 4 seconds Euler proved in one of his classic theorems that prime numbers are infinite in number. But can every number be expressed as a summation of four pos

欧拉计划第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 million. 素数的和 所有小于10的素数的和是2 + 3 + 5 + 7 = 17. 求所有小于两百万的素数的和. 解题思路 没有特别好的想法,下奶能想到的就是枚举算出200万以内的所有素数,然后求这些素数的和. 实现代码如下: #include <bits/st

欧拉项目010:2000000以内的素数和

Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. 还是使用Sieve of Eratosthenes 算法 我的python代码例如以下: #coding:utf-8 #从2到sqrt(n) # 不用全部的都用遍历.从i**2,步长为i,i*2,i*3肯定都不是质素. # 从i*

PE 001~010

题意: 001(Multiples of 3 and 5):对小于1000的被3或5整除的数字求和. 002(Even Fibonacci numbers):斐波那契数列中小于等于4 000 000的偶数求和. 003(Largest prime factor):求600 851 475 143的最大质因数. 004(Largest palindrome product):求由两个三位数相乘得到的最大回文数. 005(Smallest multiple):求能被1~20中所有数整除的最小正整数.