''' This is just an extension of Problem 9 of project euler. I just initiated the value, then took a squareroot( since the values req. are 3) Then did a gcd b/w the 2 values to find the later value. Then did a sum to get the Length. Then added them and printed them out. ''' from Euler import gcd, sqrt L = 1500000 sqrt_L = int(sqrt(L)) lengths = [0]*L #initating the arrays. for i in range(1, sqrt_L, 2): for j in range(2, sqrt_L- i , 2): if gcd(i, j) == 1: sum = abs(j*j - i*i) + 2*i*j + i*i + j*j for s in range(sum, L, sum): lengths[s]+=1 print lengths.count(1)
Assume there are no solutions in positive integers when D is square. By finding minimal solutions in x for D = {2, 3, 5...}, we obtain the following: 3^2 – 2×2^2 = 1 2^2 – 3×1^2 = 1 > 9^2 – 5×4^2 = 1 5^2 – 6×2^2 = 1 8^2 – 7×3^2 = 1 Hence, for D ≤ 6, the largest x is obtained when D=5. Find the value of D ≤ 1000 in minimal solutions of x for which the largest value of x is obtained. ''' from Euler import sqrt, cfrac, convergents def Pell(D): chain = cfrac(D) if len(chain)==1: return None for f in convergents(chain): x = f.numerator y = f.denominator if x**2 - D*y**2 == 1: return x ans = max([D for D in range(1000) if not sqrt(D).is_integer()], key=Pell) print(ans)
from Euler import prime_sieve, sqrt L = 10**7 primes = prime_sieve(int(1.30 * sqrt(L))) del primes[:int(0.6 * len(primes))] def Eluer70(limit): min_q, min_n, i = 2, 0, 0 for p1 in primes: i += 1 for p2 in primes[i:]: if (p1 + p2) % 9 != 1: continue n = p1 * p2 if n > limit: return min_n phi = (p1 - 1) * (p2 - 1) q = n / float(phi) if sorted(str(phi)) == sorted(str(n)): if min_q > q: min_q = q min_n = n print Euler70(L)
""" This is just an extension of Problem 9 of project euler. I just initiated the value, then took a squareroot( since the values req. are 3) Then did a gcd b/w the 2 values to find the later value. Then did a sum to get the Length. Then added them and printed them out. """ from Euler import gcd, sqrt L = 1500000 sqrt_L = int(sqrt(L)) lengths = [0] * L # initating the arrays. for i in range(1, sqrt_L, 2): for j in range(2, sqrt_L - i, 2): if gcd(i, j) == 1: sum = abs(j * j - i * i) + 2 * i * j + i * i + j * j for s in range(sum, L, sum): lengths[s] += 1 print lengths.count(1)
from Euler import prime_sieve, is_perm, sqrt min_q, i, L = 2, 0, 10**7 primes = prime_sieve(1.30*sqrt(L)) ll = 0.7*sqrt(L) for n in range(len(primes)): if primes[n]>ll: break del primes[:n] for p1 in primes: i+=1 for p2 in primes[i:]: n = p1 * p2 if n > L: break phi = (p1-1) * (p2-1) q = n / float(phi) if is_perm(phi, n) and min_q>q: min_q, min_n = q, n print "Answer to PE70 = ",min_n