import prime prime_list = prime.myprime(1000000) prime_dict = {} for ps in prime_list: prime_dict[ps] = 1 def isprime(n): if prime_dict.has_key(n): return True for ps in prime_list: if ps * ps > n: return True if n % ps == 0: return False return True side = 3 total_diag = 5 p = [3, 5, 7] ratio = len(p) * 1.0 / total_diag while ratio > 0.1: side = side + 2 total_diag += 4 p1 = side * side - side + 1 if isprime(p1): p.append(p1) p1 = p1 - side + 1 if isprime(p1): p.append(p1)
#!/usr/bin/env python # -*- coding: utf-8 -*- # Author: Junjie Bian # File Name: pro21.py # Description: import prime from datetime import datetime print datetime.now() p = prime.myprime(30000) def explode(num): d = {} global p i = 0 while num != 1: if num % p[i] == 0: num /= p[i] d[p[i]] = d.get(p[i], 0) + 1 else: i += 1 return d MAX_NUM = 28123 def sumup(num):
if len(numStr) == 1: return [numStr] l = list(numStr) P = [] for i in l: T = copy(l) T.remove(i) newNumStr = ''.join(T) rs = permutation(newNumStr) for r in rs: P.append(i + r) return P plist = myprime(10000) pdict = {} for p in plist: pdict[p] = 1 for p in plist: if p < 1000: continue if not pdict.has_key(p): continue ps = permutation(str(p)) ps = [int(pp) for pp in ps] ps = list(set(ps)) ps = [i for i in ps if pdict.has_key(i) and i > 1000] # print ps
import prime primes = prime.myprime(10000) primes_dict = {} for p in primes: primes_dict[p] = 1 def isPrime(n): if primes_dict.has_key(n): return True for p in primes: if p * p > n: return True if n % p == 0: return False return True def concate(m, n): return m * (10**len(str(n))) + n def isPair(m, n): return isPrime(concate(m, n)) and isPrime(concate(n, m)) def filter_bad(ps): index = [0] * len(ps) for i in range(len(ps)): print i for j in range(i + 1, len(ps)): if isPair(ps[i], ps[j]):
import prime prime_list = prime.myprime(1000000) prime_dict = {} for val in prime_list: prime_dict[val] = True def expand_to_primes(n): d = {} i = 0 while i<len(prime_list): if n% prime_list[i]==0: d[prime_list[i]] = d.get(prime_list[i],0)+1 n /= prime_list[i] else: i=i+1 if n==1: break return d best_n = -1 best_ans=-1 N = 1000000+1 ans_dict={} for val in prime_list: ans_dict[val] = val -1 for val in prime_list: cur = val*val k = 2 while cur<N:
import prime primes = prime.myprime(10000) primes_dict = {} for p in primes: primes_dict[p] = 1 def isPrime(n): if primes_dict.has_key(n): return True for p in primes: if p*p>n: return True if n%p==0: return False; return True def concate(m,n): return m*(10**len(str(n)))+n def isPair(m,n): return isPrime(concate(m,n)) and isPrime(concate(n,m)) def filter_bad(ps): index = [0] * len(ps) for i in range(len(ps)): print i for j in range(i+1, len(ps)): if isPair(ps[i], ps[j]): index[i] += 1 print ps[j], print print index
#!/usr/bin/env python # -*- coding: utf-8 -*- # Author: Junjie Bian # File Name: pro21.py # Description: import prime from datetime import datetime print datetime.now() p=prime.myprime(30000) def explode(num): d={} global p i=0 while num!=1: if num % p[i]==0: num/=p[i] d[p[i]]=d.get(p[i],0)+1 else: i+=1 return d MAX_NUM=28123 def sumup(num): d=explode(num) s=1 for k in d.keys(): s=s*(1- k**(d[k]+1))/(1-k)
if len(numStr) == 1: return [numStr] l = list(numStr) P = [] for i in l: T = copy(l) T.remove(i) newNumStr = "".join(T) rs = permutation(newNumStr) for r in rs: P.append(i + r) return P plist = myprime(10000) pdict = {} for p in plist: pdict[p] = 1 for p in plist: if p < 1000: continue if not pdict.has_key(p): continue ps = permutation(str(p)) ps = [int(pp) for pp in ps] ps = list(set(ps)) ps = [i for i in ps if pdict.has_key(i) and i > 1000] # print ps
if (num == 2 or num == 3 or num == 5): return True if (num % 2 == 0 or num % 3 == 0 or num % 5 == 0): return False sq = int(math.sqrt(num)) i = 3 while i <= sq: if num % i == 0: return False i += 2 return True pb = prime.myprime(1000) def myfunc(a, b, x): return x * x + a * x + b def quad(a, b): n = 0 s = 0 while True: if not isPrime(myfunc(a, b, n)): break n += 1 s += 1 return s
import prime N = int(1e7) prime_list = prime.myprime(N) prime_dict = {} for val in prime_list: prime_dict[val] = True def expand_to_primes(n): d = {} i = 0 while i < len(prime_list): if n % prime_list[i] == 0: d[prime_list[i]] = d.get(prime_list[i], 0) + 1 n /= prime_list[i] else: i = i + 1 if n == 1: break return d def is_permu(m, n): m_str = ''.join(sorted(str(m))) n_str = ''.join(sorted(str(n))) if m_str == n_str: return True return False best_n = -1 best_ans = -1
if num == 2 or num == 3 or num == 5: return True if num % 2 == 0 or num % 3 == 0 or num % 5 == 0: return False sq = int(math.sqrt(num)) i = 3 while i <= sq: if num % i == 0: return False i += 2 return True pb = prime.myprime(1000) def myfunc(a, b, x): return x * x + a * x + b def quad(a, b): n = 0 s = 0 while True: if not isPrime(myfunc(a, b, n)): break n += 1 s += 1 return s
import prime N = int(1e7) prime_list = prime.myprime(N) prime_dict = {} for val in prime_list: prime_dict[val] = True def expand_to_primes(n): d = {} i = 0 while i<len(prime_list): if n% prime_list[i]==0: d[prime_list[i]] = d.get(prime_list[i],0)+1 n /= prime_list[i] else: i=i+1 if n==1: break return d def is_permu(m, n): m_str = ''.join(sorted(str(m))) n_str = ''.join(sorted(str(n))) if m_str == n_str: return True return False best_n = -1 best_ans=-1 ans_dict={}