Esempio n. 1
0
        c *= 2
        if c > a:
            break
            
        if a-c in primeList:
            return True
            
    return False

# ********************************************************************
from utils import prime, sortedList
import time

startTime = time.time()

primeList = sortedList([])
primeList.add(2)

squareList = sortedList([])
squareList.addList([1,4])


start = 1 # en fait, 3
n = start
bool = True
while bool:
    n += 2
    squareList.add(n**2)
    squareList.add((n+1)**2)
    
    if prime(n):
Esempio n. 2
0
# 1, 5, 12, 22, 35, 51, 70, 92, 117, 145, ...

# It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 - 22 = 48, 
# is not pentagonal.

# Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference are 
# pentagonal and D = |Pk - Pj| is minimised; what is the value of D?

from utils import sortedList
import time

startTime = time.time()

pentagonal = lambda n : n*(3*n - 1)//2

pentagonalList = sortedList([])

size = 2750
for n in range(1, size):
    pentagonalList.add(pentagonal(n))
    

D = pentagonalList[-1] - pentagonalList[0]
for j in range(len(pentagonalList)):
    if not j % (size//100):
        print('.', end="", flush=True)
        
    for k in range(j, len(pentagonalList)):
            
        pj = pentagonalList[j]
        pk = pentagonalList[k]
Esempio n. 3
0
	if len(list) != 9:
		return False
		
	for i in range(len(list)):
		if list[i] != i+1:
			return False
	
	return True
	
# retourne une liste contenant tout les chiffres de a, b et a*b
def mk(a,b):
	result = cut(a)
	result.extend(cut(b))
	result.extend(cut(a*b))
	result.sort()
	
	return result
	
# ******************************************************************************
result = sortedList([])

for i in range(1,1000):
	for j in range(1,10000):
		if i*j >= 10000:
			break;
			
		if pandigital(mk(i,j)):
			result.add(i*j)
			
print(result.sum())
Esempio n. 4
0
    # 3^2=9, 3^3=27, 3^4=81, 3^5=243
    # 4^2=16, 4^3=64, 4^4=256, 4^5=1024
    # 5^2=25, 5^3=125, 5^4=625, 5^5=3125

# If they are then placed in numerical order, with any repeats removed, we
 # get the following 
# sequence of 15 distinct terms:

# 4, 10, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125

# How many distinct terms are in the sequence generated by a^b for 
# 2 <= a < 100 and 2 <= b <= 100? 

from utils import sortedList

list = sortedList([])
	
for a in range(2,101):
	for b in range(2,101):
		list.add(a**b)
		
print(list.size())