def phi2(num): # print [i for i in range(2,num) if areRelativePrime(num , i)] if helpers.is_prime(num): return -1 global maxPhi phi_num = 1 phi_cache = [] for i in range(2, num): for j in phi_cache: if i % j == 0: break else: if helpers.are_relative_prime(num, i): phi_num += 1 if (num / phi_num) <= maxPhi: return -1 else: phi_cache.append(i) return phi_num
def phi3(num): # print [i for i in range(2,num) if areRelativePrime(num , i)] # if (helpers.isPrime(num)): # return -1 global maxPhi phi_num = 1 nums = range(2, num) flag = True while flag: flag = False for i in nums: if helpers.are_relative_prime(num, i): phi_num += 1 if (num / phi_num) <= maxPhi: return -1 else: nums = [j for j in nums if ((j % i) > 0) and j >= i] flag = True break return phi_num
import helpers import math # inputFile = open('resources/', 'r') start_time = time.clock() max_val = 1000 counter = 0 things = [] other_things = set() for i in range(2, max_val): if counter > max_val: break for j in range(1, i): if ((i + j) % 2) and helpers.are_relative_prime(i, j): counter += 1 t = tuple(sorted([2 * i * j, i * i - j * j])) things.append(t[1]) other_things.add(t) if counter > max_val: break max_thing = max(things) new_things = set(things) for thing in other_things: new_thing = thing while new_thing[1] < max_thing: hyp = math.sqrt(new_thing[0] * new_thing[0] + new_thing[1] * new_thing[1]) asd = hyp + new_thing[0] + new_thing[1] if asd == 1000:
import helpers import math # inputFile = open('resources/', 'r') start_time = time.clock() max_val = 1000 counter = 0 things = [] other_things = set() for i in range(2, max_val): if counter > max_val: break for j in range(1, i): if ((i + j) % 2) and helpers.are_relative_prime(i, j): counter += 1 t = tuple(sorted([2 * i * j, i * i - j * j])) things.append(t[1]) other_things.add(t) if counter > max_val: break max_thing = max(things) new_things = set(things) for thing in other_things: new_thing = thing while new_thing[1] < max_thing: hyp = math.sqrt(new_thing[0] * new_thing[0] + new_thing[1] * new_thing[1]) asd = hyp + new_thing[0] + new_thing[1]
# inputFile = open('resources/', 'r') start = time.clock() # print(fraction(23)) num = 1 existing = {} target = 1500000 # for num in range(1, top): while num ** 2 < target: num2 = num + 1 asdf = 0 increment = 2 if num % 2 else 1 while asdf < target: if helpers.are_relative_prime(num, num2): asdf = 2 * (num2 * (num + num2)) k = 1 asdf2 = k * asdf while asdf2 < target: existing[asdf2] = existing.get(asdf2, set()) existing[asdf2].add((num * k, num2 * k)) k += 1 asdf2 += asdf num2 += increment num += 1 counter = 0 for i in existing: if len(existing[i]) == 1: counter += 1
# inputFile = open('resources/', 'r') start = time.clock() # print(fraction(23)) num = 1 existing = {} target = 1500000 # for num in range(1, top): while num**2 < target: num2 = num + 1 asdf = 0 increment = 2 if num % 2 else 1 while asdf < target: if helpers.are_relative_prime(num, num2): asdf = 2 * (num2 * (num + num2)) k = 1 asdf2 = k * asdf while asdf2 < target: existing[asdf2] = existing.get(asdf2, set()) existing[asdf2].add((num * k, num2 * k)) k += 1 asdf2 += asdf num2 += increment num += 1 counter = 0 for i in existing: if len(existing[i]) == 1: counter += 1