示例#1
0
def main():
    # generics
    _time = time()
    result = 1
    problem = 70
    # problem specific variables
    _limit = 10**7
    _lower = 2
    q = _limit
    s = 1
    r = 0
    a = 3
    b = 7
    # compute answer
    while q >= _lower:
        p = (a * q - 1) / float(b)
        if (p * s > r * q):
            s = q
            r = p
            _lower = float(s) / (a * s - b * r)
        q += -1
    factor = gcd(r, s)
    r /= factor
    s /= factor
    # output to screen
    print r, s
    project_euler.__output(_time, problem, r)
    return
示例#2
0
def main():
    # generics
    s = time()
    result = 1
    problem = 70
    # problem specific variables
    _lower = 2000
    _upper = 5000
    _limit = 10**7
    _primes = project_euler.__eseive(_lower, _upper)
    _n = 0
    _bn = 1
    _phi = 1
    _bphi = 0
    _ratio = 0
    _bratio = float("inf")
    # compute answer
    for i in xrange(len(_primes)):
        for j in xrange(i + 1, len(_primes)):
            _n = long(_primes[i] * _primes[j])
            if _n > _limit:
                break
            _phi = long((_primes[i] - 1) * (_primes[j] - 1))
            _ratio = float(_n) / _phi
            if project_euler.__isperm(_n, _phi) and _bratio > _ratio:
                _bn = _n
                _bphi = _phi
                _bratio = _ratio
    # output to screen
    project_euler.__output(s, problem, _bn)
    print _bratio
    return
示例#3
0
def main():
    # generics
    _time = time()
    result = 0
    problem = 75
    # problem specific variables
    limit = 1500000
    mlimit = int(math.sqrt(limit / 2))
    tri = [0 for i in range(limit + 1)]
    # compute answer
    for m in range(2, mlimit):
        for n in range(1, m):
            if ((n + m) % 2) == 1 and project_euler.__gcd(n, m) == 1:
                a = (m * m) + (n * n)
                b = (m * m) - (n * n)
                c = 2 * m * n
                p = a + b + c
                while p < limit:
                    tri[p] += 1
                    if tri[p] == 1: result += 1
                    if tri[p] == 2: result -= 1
                    p += a + b + c
    # output to screen
    project_euler.__output(time() - _time, problem, result)
    return
示例#4
0
def main():
    # generics
    _time = time()
    result = 0
    problem = 76
    # problem specific variables
    total = 100
    # compute answer

    # output to screen
    project_euler.__output(time() - _time, problem, result)
    return
示例#5
0
def main():
    # generics
    _time = time()
    result = 1
    problem = 74
    # problem specific variables
    limit = 10**6
    chains_eq60 = 0
    target_chain_length = 60
    # compute answer
    for i in range(1, limit):
        chain_length = fact_loop(i)
        if chain_length == target_chain_length:
            chains_eq60 += 1
            #print(i, chains_eq60)
    # output to screen
    project_euler.__output(_time, problem, chains_eq60)
    return
示例#6
0
def main():
    # generics
    _time = time()
    result = 0
    problem = 79
    # problem specific variables
    numbers = set()
    keylog = []
    # compute answer

    f = open(
        "C:/Users/Tom/Documents/Projects/Python/Project_Euler/problem_079.txt",
        "r")

    for char_entry in f:
        print(char_entry)

    # output to screen
    project_euler.__output(time() - _time, problem, result)
    return