Ejemplo n.º 1
0
def main( prime_cap ):
#tries to find lowests sum set of 5 primes which all concatenate pair-wise to form primes
#only searches for primes below prime_cap

	import import_primes
	primes = import_primes.main()
	#pulls all primes below one million

	if prime_cap > ( 10 ** 6 ):
		print('error, prime_cap > 10**6')

	i = 0
	while primes[ i ] < prime_cap and i < ( len( primes ) - 1 ):
		i += 1
	primes = primes[ 0 : i ]
	#removes all primes above prime_cap from list of primes

	good_sets = []
	#will store all sets of primes found

	for a in primes:
		for b in primes:
			if b > a:
				if check_concat( b , a ):
					for c in primes:
						if c > b:
							if check_concat( c , a ) and check_concat( c , b ):
								for d in primes:
									if d > c:
										if check_concat( d , a ) and check_concat( d , b ) and check_concat( d , c ):
											for e in primes:
												if e > d:
													if check_concat( e , a ) and check_concat( e , b ) and check_concat( e , c ) and check_concat( e , d ):
														good_sets.append( [ a , b , c , d , e ] )

#TEST
	print('good_sets=',good_sets)
#TEST


	min_sum = sum( good_sets[ 0 ] )
	stored_set = good_sets[ 0 ]
	for good_set in good_sets:
		if sum( good_set ) < min_sum:
			min_sum = sum( good_set )
			stored_set = good_set

	return ( stored_set , min_sum )
Ejemplo n.º 2
0
def factor_below(x):
    #finds prime factors of all numbers from 1 to x

    primes = import_primes.main()

    factor_list = [0, 1]
    #zeroth and first entries are placeholders, after that i-th entry will hold factors of i

    for i in range(2, x + 1):
        #factors i and adds a set (unqiue entries) of its factors to the factor_list

        factor_list.append(set(factor_given_primes.main(i, primes)))

        #TEST
        print(i)


#TEST

    return factor_list
Ejemplo n.º 3
0
def main(x):
    #finds number less than or equal to x (in problem x = one million) that contains the most prime factors
    #this number solves the desired problem -- see wikipedia page

    primes = import_primes.main()
    #pulls list of primes less than one million

    i = 0

    num = 2

    while num <= x:
        #multiples number by primes until it is greater than x

        i += 1

        num = num * primes[i]
        #multiply number by next prime

    num = num // primes[i]
    #divides out last prime number that was multiplied, to return number to below x

    return num
Ejemplo n.º 4
0
#Prime summations

#It is possible to write ten as the sum of primes in exactly five different ways:

#7 + 3
#5 + 5
#5 + 3 + 2
#3 + 3 + 2 + 2
#2 + 2 + 2 + 2 + 2

#What is the first value which can be written as the sum of primes in over five thousand different ways?

import import_primes
primes_list = import_primes.main()
#fetches list of all primes below one million

import copy
#for use later

#COPIED BELOW FROM partition_function.py
#WITH MINOR CHANGES ADDED

#see: https://en.wikipedia.org/wiki/Partition_(number_theory)

#NOTE: ASSUMES INPUT OF 7 OR GREATER

import list_prod_sum
#list_prod_sum.main(a,b) takes two lists a multiplies them pairwise. returns the sum.


def rem(x, a, b):
Ejemplo n.º 5
0
#Prime square remainders

#Let pn be the nth prime: 2, 3, 5, 7, 11, ..., and let r be the remainder when (pn−1)^n + (pn+1)^n is divided by pn^2.

#For example, when n = 3, p3 = 5, and 4^3 + 6^3 = 280 ≡ 5 mod 25.

#The least value of n for which the remainder first exceeds 10^9 is 7037.

#Find the least value of n for which the remainder first exceeds 10^10.

import import_primes

primes = import_primes.main()
#gets list of all primes below 1 million


def main(x):
    #finds least value for n where remainder exceeds x (in problem as defined, x = 10^10)

    i = 1
    #prime index
    p = 2
    #first prime
    rem = 1
    #first remainder

    while rem < x:
        i += 1
        p = primes[(i - 1)]
        #pulls prime from list
        rem = (((p - 1)**i) + ((p + 1)**i)) % (p**2)