Project Euler Problem 7-10001st prime】的更多相关文章

素数线性筛 MAXN = 110100 prime = [0 for i in range(210000)] for i in range(2,MAXN): if prime[i] == 0: prime[0] += 1 prime[prime[0]] = i j = 1 while j <= prime[0] and prime[j]<=MAXN/i: prime[prime[j]*i] = 1 if i%prime[j] == 0: break j += 1 print prime[100…
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? max1 = 10001 a = [2] i = 3 while len(a) < max1: flag = 0 for j in a: if j > i**0.5: break if i%j == 0: flag = 1 b…
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. The code resemble : import math limit = 2000000 crosslimit = int(math.sqrt(limit)) #sieve = [False] * limit sieve =…
ORZ foreverlasting聚聚,QQ上问了他好久才会了这题(所以我们又聊了好久的Gal) 我们先来尝试推导一下\(S\)的性质,我们利用狄利克雷卷积来推: \[2^\omega=I\ast|\mu|\] 这个很好理解吧,考虑一下它的组合意义即可 然后两边同卷上\(I\)有: \[2^\omega \ast I=I\ast I\ast |\mu|=d\ast |\mu|\] 后面还是同样,考虑\(d\ast |\mu|\)的组合意义,一正一反的情况下其实就是\(d(n^2)\) 因此我们…
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; i…
还是素数线性筛 MAXN = 2000000 prime = [0 for i in range(MAXN+1)] res = 0 for i in range(2,MAXN+1): if prime[i] == 0: res += i prime[0] += 1 prime[prime[0]] = i j = 1 while j <= prime[0] and prime[j]<=MAXN/i: prime[prime[j]*i] = 1 if i%prime[j] == 0: break…
题目的大意很简单 做法的话. 我们就枚举1~10000的数的立方, 然后把这个立方中的有序重新排列,生成一个字符串s, 然后对于那些符合题目要求的肯定是生成同一个字符串的. 然后就可以用map来搞了 这里偷懒用了python import string dic = {} def getstr(n): sn = str(n) arr = [] for c in sn: arr.append(c) arr.sort() return ''.join(arr) for i in xrange(1, 1…
这题略水啊 首先观察一下. 10 ^ x次方肯定是x + 1位的 所以底数肯定小于10的 那么我们就枚举1~9为底数 然后枚举幂级数就行了,直至不满足题目中的条件即可break cnt = 0 for i in range(1, 10): e = 1 while True: if len(str(i**e)) != e: break e += 1 cnt += 1 print cnt…
题意很明了. 然后我大概的做法就是暴搜了 先把每个几边形数中四位数的处理出来. 然后我就DFS回溯着找就行了. 比较简单吧. #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <cmath> #include <vector> using namespace std; vector<int>g[7],…
题意须要注意的一点就是, 序列是从外层最小的那个位置顺时针转一圈得来的.而且要求10在内圈 所以,这题暴力的话,假定最上面那个点一定是第一个点,算下和更新下即可. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cstdlib> #include <ctime> #include <set> #i…