Exemplo n.º 1
0
def genlistprimeslimit(LIMIT):
    l = []
    genp = mymaths.prime()
    while True:
        p = genp.next()
        if p < ((LIMIT / 2) + 1):
            l.append(p)
        else:
            break
    return l
Exemplo n.º 2
0
def genlprimes(n):
    """ genera una lista de primos que pueda dividir n """
    l = []
    p = mymaths.prime()
    prime = p.next()
    # quiero una lista de primos que dividan a n, por lo tanto con
    # buscar solo la mitad me va bien
    limit = n + 1
    while prime < limit:
        l.append(prime)
        prime = p.next()

    return l
Exemplo n.º 3
0
#!/usr/bin/python

# Problem 9
# A Pythagorean triplet is a set of three natural numbers, a  b  c, for which,
#
# a**2 + b**2 = c**2
# For example, 3**2 + 4**2 = 9 + 16 = 25 = 5**2.
#
# There exists exactly one Pythagorean triplet for which a + b + c = 1000.
# Find the product abc.

import os
import sys

lib_path = os.path.abspath("../../lib")
sys.path.append(lib_path)

import mymaths

p = mymaths.prime()
limite = 2000000
sumprimos = 0
primo = 0
while primo < limite:
    sumprimos += primo
    primo = p.next()

print("Resultado 0010", sumprimos)
Exemplo n.º 4
0
from datetime import datetime

lib_path = os.path.abspath('../../lib')
sys.path.append(lib_path)

import mymaths

MAXIMO = 10000000000


def get_resto(n, p):
    return (((p - 1) ** n) + (p + 1) ** n) % (p ** 2)


# controlamos el tiempo de ejecución
start_time = datetime.now()

# generador de primos
primegen = mymaths.prime()

n = 0
while True:
    p = primegen.next()
    n += 1
    r = get_resto(n, p)
    if r > MAXIMO:
        break

print "Tiempo total: ", datetime.now() - start_time
print "Resultado de 0123 ", n