Ejemplo n.º 1
0
def get_prime_factors(num, primes=()):
    pf = [1]
    for prime in primes:
        if prime > num:
            break
        if num in set_primes:
            pf.append(num)
            break
        while num % prime == 0:
            if prime not in pf:
                pf.append(prime)
            num /= prime
    return pf


primes = (helpers.shieve_primes_to(100000))
set_primes = set(primes)

flist = {}
flist2 = {}
for i in range(1, 10 ** 5 + 1):
    flist[i] = reduce((lambda x, y: x * y), get_prime_factors(i, primes))
    if i % 1000 == 0:
        print(i)

    flist2[(flist[i], i)] = i

# print(flist)
# print(sorted(flist2))
k = 1
result = None
Ejemplo n.º 2
0
import time
import helpers
import math
import itertools

# inputFile = open('resources/', 'r')

start = time.clock()

target = 10000000
ordered_primes = helpers.shieve_primes_to(target)
primes = set(ordered_primes)


def totient(target_number):
    global ordered_primes, minimum
    new_num = target_number
    for i in ordered_primes:
        if target_number % i == 0:
            new_num *= (i - 1) / i
            while target_number % i == 0:
                target_number /= i
            if target_number in primes:
                new_num *= (target_number - 1) / target_number
                break
            if target_number / new_num > minimum:
                return 1
        if i > target_number:
            break
    return int(new_num)
Ejemplo n.º 3
0
# inputFile = open('resources/', 'r')


def get_prime_factors(num, primes=()):
    pf = [1]
    for prime in primes:
        if prime > num:
            break
        if num in set_primes:
            pf.append(num)
            break
        while num % prime == 0:
            if prime not in pf:
                pf.append(prime)
            num /= prime
    return pf


start_time = time.clock()
prime_factors = {}
num = 600851475143
primes = (helpers.shieve_primes_to(int(num**.5)))
print('found primes')
set_primes = set(primes)

pf = get_prime_factors(num, primes)
print("\033[0;35mpf", pf, "\033[0m")

print(time.clock() - start_time)
Ejemplo n.º 4
0
import time
import helpers
import math

# inputFile = open('resources/', 'r')
start = time.clock()

primes = helpers.shieve_primes_to(100000)
primes_set = set(primes)
divisor_cache = {}
i = 1
num = 0
max_prime = 0
while True:
    num = num + i
    i += 1
    divisors = {}
    tmp_num = num
    if num % 2:
        continue
    for prime in primes:
        power = 0
        while tmp_num % prime == 0:
            tmp_num /= prime
            power += 1
        if power > 0:
            divisors[prime] = power
        if tmp_num == 1:
            break
        if tmp_num in primes_set:
            divisors[tmp_num] = 1
Ejemplo n.º 5
0
import time
import helpers
import math

# inputFile = open('resources/', 'r')

start = time.clock()
primes = [str(i) for i in helpers.shieve_primes_to(90000000)]
primesSet = set(primes)
print('PRIMES RRREADY!!!')
print(time.clock() - start)

# len_primes = {}
# for i in primes:
#     len_primes[len(i)] = set()
# for i in primes:
#     len_primes[len(i)] |= {i}
# l = {}
# for i in primes:
#     l[i] = []
biggest_len = len(primes[-1])
print('INDEXES RRREADY!!!')
print(biggest_len)
print(time.clock() - start)


def check(sub_list, target_length):
    # print(sub_list)
    if target_length == 0:
        return [sub_list[0]]
    if len(sub_list) < target_length:
Ejemplo n.º 6
0
import time
import helpers

start_time = time.clock()

global_primes = helpers.shieve_primes_to(20000)
set_primes = set(global_primes)

global_things = {}


def calc_prime_factors(num):
    power = num - 1
    prime_things = {}
    for i in range(num, 1, -1):
        for pf, pp in global_factors[i].items():
            prime_things[pf] = prime_things.get(pf, 0) + power * pp
        power -= 2

    return prime_things


factor_cache = {}
mul_cache = {}


def get_prime_factors(num, factors=None):
    if num in factor_cache:
        return factor_cache[num]
    new_num = num
    primes = global_primes
Ejemplo n.º 7
0
# inputFile = open('resources/', 'r')


def get_prime_factors(num, primes=()):
    pf = [1]
    for prime in primes:
        if prime > num:
            break
        if num in set_primes:
            pf.append(num)
            break
        while num % prime == 0:
            if prime not in pf:
                pf.append(prime)
            num /= prime
    return pf


start_time = time.clock()
prime_factors = {}
num = 600851475143
primes = (helpers.shieve_primes_to(int(num**.5)))
print('found primes')
set_primes = set(primes)

pf = get_prime_factors(num, primes)
print("\033[0;35mpf", pf, "\033[0m")

print(time.clock() - start_time)
Ejemplo n.º 8
0
import time
import helpers
import math

# inputFile = open('resources/', 'r')

start_time = time.clock()

print(helpers.shieve_primes_to(1000000)[10000])
print(time.clock() - start_time)
Ejemplo n.º 9
0
import time
import helpers
import math

# inputFile = open('resources/', 'r')

start = time.clock()
target = 1000000
# primes = helpers.primesTo(target)
print(time.clock() - start)

total = 0
ordered_primes = helpers.shieve_primes_to(target)
primes = set(ordered_primes)

max_loops = 0


def totient(target_number):
    global ordered_primes, max_loops
    new_num = target_number
    for i in ordered_primes:
        if target_number % i == 0:
            new_num *= (i - 1) / i
            while target_number % i == 0:
                target_number /= i
            if target_number in primes:
                new_num *= (target_number - 1) / target_number
                break
        if i > target_number:
            break
Ejemplo n.º 10
0
import time
import helpers
import math

# inputFile = open('resources/', 'r')

start_time = time.clock()

s = sum(helpers.shieve_primes_to(2 * (10**6)))
print("\033[0;35ms", s, "\033[0m")
print(time.clock() - start_time)
Ejemplo n.º 11
0
import time
import helpers
import math

# inputFile = open('resources/', 'r')

start = time.clock()

primes = list(reversed(helpers.shieve_primes_to(10000)))
l = len(primes)


def makeSum(maximum, summa, index):
    variations = 0
    for i in range(index, l):
        coin_sum = summa + primes[i]
        if coin_sum < maximum:
            variations += makeSum(maximum, coin_sum, i)
        elif coin_sum == maximum:
            variations += 1
    return variations


for i in [i for i in range(2, 1000)]:
    thingies = []
    res = makeSum(i, 0, 0)
    if res > 5000:
        print(i, res)
        break

print(time.clock() - start)