示例#1
0
def main():
    for i, factors in enumerate(prime_factorization_under(10 ** 6)):
        number = i + 2
        num_solution = (product(2 * i + 1 for i in factors.values()) + 1) // 2
        # print(number, num_solution)
        if num_solution > 1000:
            print(number, num_solution)
            break
示例#2
0
def main():
    for i, factors in enumerate(prime_factorization_under(10**6)):
        number = i + 2
        num_solution = (product(2 * i + 1 for i in factors.values()) + 1) // 2
        # print(number, num_solution)
        if num_solution > 1000:
            print(number, num_solution)
            break
示例#3
0
def check_n(num, factors):
    num_of_fac = len(factors)
    if not primality[num + 1]:
        return False
    for i in range(1, num_of_fac//2+1):
        for comb in combinations(range(num_of_fac), i):
            part1 = product(factors[j] for j in comb)
            if not primality[part1 + num//part1]:
                return False
    return True
示例#4
0
def check_n(num, factors):
    num_of_fac = len(factors)
    if not primality[num + 1]:
        return False
    for i in range(1, num_of_fac // 2 + 1):
        for comb in combinations(range(num_of_fac), i):
            part1 = product(factors[j] for j in comb)
            if not primality[part1 + num // part1]:
                return False
    return True
示例#5
0
def main():
    N = 4 * 10**6
    N2 = N * 2 + 1
    primes = prime_under(50)
    # print(log(N2, 3), len(primes), list(enumerate(primes)), sep='\n')

    choice = []
    for i3 in range(ceil(log(N2, 3)) + 1):
        current3 = 3**i3
        if current3 > N2:
            choice.append([3] * i3)
            break
        for i5 in range(ceil(log(N2, 5)) + 1):
            current5 = current3 * 5**i5
            if current5 > N2:
                choice.append([3] * i3 + [5] * i5)
                break
            for i7 in range(ceil(log(N2, 7)) + 1):
                current7 = current5 * 7**i7
                if current7 > N2:
                    choice.append([3] * i3 + [5] * i5 + [7] * i7)
                    break
                for i9 in range(ceil(log(N2, 9)) + 1):
                    current9 = current7 * 9**i9
                    if current9 > N2:
                        choice.append([3] * i3 + [5] * i5 + [7] * i7 +
                                      [9] * i9)
                        break
                    for i11 in range(ceil(log(N2, 11)) + 1):
                        current11 = current9 * 11**i11
                        if current11 > N2:
                            choice.append([3] * i3 + [5] * i5 + [7] * i7 +
                                          [9] * i9 + [11] * i11)
                            break

    # print(len(choice))
    # min_n = 10 ** 20  # inf
    # min_comp = []
    # for seq in choice:
    #     current_n = product(i**(j//2) for i, j in zip(primes, reversed(seq)))
    #     # print(current_n, seq)
    #     if current_n < min_n:
    #         min_n = current_n
    #         min_comp = seq
    # print(min_comp)

    min_n = min(
        product(i**(j // 2) for i, j in zip(primes, reversed(seq)))
        for seq in choice)
    print(min_n)
示例#6
0
def main():
    N = 4 * 10 ** 6
    N2 = N * 2 + 1
    primes = prime_under(50)
    # print(log(N2, 3), len(primes), list(enumerate(primes)), sep='\n')

    choice = []
    for i3 in range(ceil(log(N2, 3))+1):
        current3 = 3 ** i3
        if current3 > N2:
            choice.append([3]*i3)
            break
        for i5 in range(ceil(log(N2, 5))+1):
            current5 = current3 * 5 ** i5
            if current5 > N2:
                choice.append([3]*i3 + [5]*i5)
                break
            for i7 in range(ceil(log(N2, 7))+1):
                current7 = current5 * 7 ** i7
                if current7 > N2:
                    choice.append([3]*i3 + [5]*i5 + [7]*i7)
                    break
                for i9 in range(ceil(log(N2, 9))+1):
                    current9 = current7 * 9 ** i9
                    if current9 > N2:
                        choice.append([3]*i3 + [5]*i5 + [7]*i7 + [9]*i9)
                        break
                    for i11 in range(ceil(log(N2, 11))+1):
                        current11 = current9 * 11 ** i11
                        if current11 > N2:
                            choice.append([3]*i3 + [5]*i5 + [7]*i7 + [9]*i9 + [11]*i11)
                            break

    # print(len(choice))
    # min_n = 10 ** 20  # inf
    # min_comp = []
    # for seq in choice:
    #     current_n = product(i**(j//2) for i, j in zip(primes, reversed(seq)))
    #     # print(current_n, seq)
    #     if current_n < min_n:
    #         min_n = current_n
    #         min_comp = seq
    # print(min_comp)

    min_n = min(product(i**(j//2) for i, j in zip(primes, reversed(seq))) 
                for seq in choice)
    print(min_n)
示例#7
0
def main():
    # brute firce
    # count = 0
    # for i in range(1, SIZE):
    #     count += div7_row(i)
    # print(count)
    # print(SIZE * (SIZE + 1) // 2 - count)

    # POW = ceil(log(SIZE, 7))
    # pow7 = [7**i for i in range(1, POW)]
    # triangle = [(i - 1) * i // 2 for i in pow7]
    # whole_triangle = [triangle[0]]
    # for i in range(1, POW - 1):
    #     whole_triangle.append(whole_triangle[-1] * 21 * 3 + triangle[i])

    # print(pow7)
    # print(triangle)
    # print(whole_triangle)

    # # top level
    # covered = (7 ** (POW - 1) * 2)
    # total = whole_triangle[-1] * (SIZE // covered)

    # print(total)
    # print(SIZE - covered)

    # by Lucus's Thm
    count = 0
    row_base7 = [0]
    for row in range(0, SIZE):
        count += product(i + 1 for i in row_base7)

        row_base7[0] += 1
        for d in range(len(row_base7)):
            if row_base7[d] == 7:
                row_base7[d] = 0
                if d < len(row_base7) - 1:
                    row_base7[d + 1] += 1
                else:
                    row_base7.append(1)
                    break
            else:
                break

    print(count)
示例#8
0
def main():
    # brute firce
    # count = 0
    # for i in range(1, SIZE):
    #     count += div7_row(i)
    # print(count)
    # print(SIZE * (SIZE + 1) // 2 - count)

    # POW = ceil(log(SIZE, 7))
    # pow7 = [7**i for i in range(1, POW)]
    # triangle = [(i - 1) * i // 2 for i in pow7]
    # whole_triangle = [triangle[0]]
    # for i in range(1, POW - 1):
    #     whole_triangle.append(whole_triangle[-1] * 21 * 3 + triangle[i])

    # print(pow7)
    # print(triangle)
    # print(whole_triangle)

    # # top level
    # covered = (7 ** (POW - 1) * 2)
    # total = whole_triangle[-1] * (SIZE // covered)

    # print(total)
    # print(SIZE - covered)

    # by Lucus's Thm
    count = 0
    row_base7 = [0]
    for row in range(0, SIZE):
        count += product(i + 1 for i in row_base7)

        row_base7[0] += 1
        for d in range(len(row_base7)):
            if row_base7[d] == 7:
                row_base7[d] = 0
                if d < len(row_base7) - 1:
                    row_base7[d + 1] += 1
                else:
                    row_base7.append(1)
                    break
            else:
                break

    print(count)
示例#9
0
def reciprocal_solution(n):
    # return sum(n*i % (i-n) == 0 for i in range(n+1, 2*n+1))  # slow
    return (product(2 * i + 1 for i in prime_factorization(n).values()) + 1) // 2
示例#10
0
def reciprocal_solution(n):
    # return sum(n*i % (i-n) == 0 for i in range(n+1, 2*n+1))  # slow
    return (product(2 * i + 1
                    for i in prime_factorization(n).values()) + 1) // 2