from math import sqrt
from random import randint
# returns the greatest divisor and
# how many times it goes into num as a list
def gd(num):
if is_prime(num):
return [1, num]
else:
i = round(num / 2) + 1
while i >= 2:
for n in range(2, i + 1):
if i * n == num:
return [i, n]
i -= 1
def list_check(f, nums):
for i in nums:
if not f(i):
return False
return True
# fermat's primality test, runs ten times
def is_prime(x):
test_num = 0
for i in range(0, 11):
test_num = randint(1, x)
if (test_num ** x % x) == (test_num % x):
continue
else:
return False
return True
def simplify(problem):
nums = {}
for i in problem:
nums[i] = 0
for i in problem:
if i != 1:
nums[i] += 1
return nums
def divisor_count(num):
nums = {}
problem = []
current_divisors = []
current_divisors = gd(num)
for i in current_divisors:
problem.append(i)
while(list_check(is_prime, problem) == False):
for i in range(0, len(problem)):
if not is_prime(problem[i]):
current_divisors = gd(problem[i])
problem[i] = current_divisors[0]
problem.append(current_divisors[1])
nums = simplify(problem)
divisors = 1
for k, v in nums.items():
divisors *= v + 1
return divisors
def sum(lower, next, f, upper, total):
if lower > upper:
return total
else:
sum(next(lower), next, f, upper, total + f(lower))
def pe_12(num, divisors):
i = 0
while(divisors < 500):
if i % 10 == 0:
print(divisors)
i += 1
num += 1
divisors = divisor_count(triangle_num(num))
print(num)
def triangle_num(x):
sum = 0
while x > 0:
sum += x
x -= 1
return sum