def smallest_multiple(n): primes = get_primes(n); result = 1 for i in primes: temp = i while temp <= n: result *= i temp *= i return result
def smallest_multiple(n): primes = get_primes(n) result = 1 for i in primes: temp = i while temp <= n: result *= i temp *= i return result
def find_solution(n, start=1): primes = get_primes(10**n) prime_set = set(primes) for i in primes: if i <= start: continue for j in range(1, int(10**(n - 1) * 9 / 2)): if i + j > 10 ** n or i + 2 * j > 10 ** n or i + j not in prime_set or i + 2 * j not in prime_set or \ origin_sequence(i) != origin_sequence(i + j) or origin_sequence(i) != origin_sequence(i + 2 * j): continue return str(i) + str(i + j) + str(i + 2 * j) return 0
def find_solution(n, start=1): primes = get_primes(10 ** n) prime_set = set(primes) for i in primes: if i <= start: continue for j in range(1, int(10 ** (n - 1) * 9 / 2)): if i + j > 10 ** n or i + 2 * j > 10 ** n or i + j not in prime_set or i + 2 * j not in prime_set or \ origin_sequence(i) != origin_sequence(i + j) or origin_sequence(i) != origin_sequence(i + 2 * j): continue return str(i) + str(i + j) + str(i + 2 * j) return 0
flag = False break if flag: present.append(primes[i]) result = _solution(primes, i + 1, present, k) if result: return result present.pop() def solution(primes, k): for i in range(0, len(primes)): present = [primes[i]] result = _solution(primes, i + 1, present, k) if result: return result present.pop() if __name__ == "__main__": n = 10000 primes = get_primes(n) assert solution(primes, 4) == [3, 7, 109, 673] result = solution(primes, 5) print(result, sum(result))
from common import is_pandigital, get_primes if __name__ == "__main__": """8位和9位的数能被3整除,所以直接找从7位的开始找, 7位的直接从7开头的开始找""" n = 10**6 * 8 PRIMES = set(get_primes(n)) while True: if n in PRIMES and is_pandigital(n, 7): break n -= 1 print(n)
from common import get_primes n = 10 ** 5 COINS = get_primes(n) summation = {} def prime_summation(n): return _prime_summation(n, n) def _prime_summation(n, maximum): key = '{}-{}'.format(n, maximum) if key in summation: return summation[key] if n < 0: return 0 if n == 0: return 1 value = sum(_prime_summation(n - i, i) for i in COINS if i <= maximum) summation[key] = value return value if __name__ == "__main__": assert prime_summation(10) == 5 for i in range(1, n): if prime_summation(i) >= 5000: print(i) break
#coding:utf-8 ''' Created on 2016年1月3日 @author: robinjia @email: [email protected] ''' from common import get_primes if __name__ == "__main__": print(sum(get_primes(2000000)))
from common import prime_factor, get_primes PRIMES = set(get_primes(10 ** 8)) def find_smallest(t): i = 1 while True: if i in PRIMES: i += 1 continue flag = True for j in range(0, t): if i + j in PRIMES or len(prime_factor(i + j)) != t: flag = False break if flag: return i i += 1 if __name__ == "__main__": assert find_smallest(2) == 14 assert find_smallest(3) == 644 print(find_smallest(4))
from common import get_primes MAXIMUM = 1000000 PRIMES = set(get_primes(MAXIMUM)) def is_circular_prime(n): for i in range(0, len(str(n))): if int(str(n)[i:n] + str(n)[0:i]) not in PRIMES: return False return True if __name__ == "__main__": assert is_circular_prime(719) == True n = 1000000 print(len([i for i in range(1, n) if is_circular_prime(i)]))
from common import get_primes PRIMES = set(get_primes(10000000)) def quadratic_prime(a, b): i = 0 while True: s = i**2 + a * i + b if s not in PRIMES: return i i += 1 if __name__ == "__main__": n = 1000 a = 0 b = 0 maximum = 0 for i in range(-n + 1, n): for j in range(-n, n + 1): print(i, j) temp = quadratic_prime(i, j) if temp > maximum: maximum = temp a = i b = j print(a, b, a * b)
from common import get_primes PRIMES = set(get_primes(10000000)) def quadratic_prime(a, b): i = 0 while True: s = i ** 2 + a * i + b if s not in PRIMES: return i i += 1 if __name__ == "__main__": n = 1000 a = 0 b = 0 maximum = 0 for i in range(-n + 1, n): for j in range(-n, n + 1): print(i, j) temp = quadratic_prime(i, j) if temp > maximum: maximum = temp a = i b = j print(a, b, a * b)
from common import get_primes n = 10**7 primes = set(get_primes(n)) def truncatable_prime(n): n = str(n) for i in range(1, len(n)): if int(n[0:i]) not in primes: return False if int(n[-i:]) not in primes: return False return int(n) in primes if __name__ == "__main__": assert truncatable_prime(3797) == True s = [i for i in range(10, n) if truncatable_prime(i)] print(s, sum(s))
from common import get_primes if __name__ == "__main__": n = 1000000 primes = get_primes(n) p = 1 for i in primes: if p * i > n: break p = p * i print(p)
from common import is_pandigital, get_primes if __name__ == "__main__": """8位和9位的数能被3整除,所以直接找从7位的开始找, 7位的直接从7开头的开始找""" n = 10 ** 6 * 8 PRIMES = set(get_primes(n)) while True: if n in PRIMES and is_pandigital(n, 7): break n -= 1 print(n)