예제 #1
0
def solve():
    i = 1000
    while True:
        print i
        a,b,c,d = factor(i), factor(i+1), factor(i+2), factor(i+3)
        if distinctFact(a,b) and distinctFact(a,c) and distinctFact(a,d) and distinctFact(b,c) \
        and distinctFact(b,d) and distinctFact(c,d):
            return i
        else:
            i += 1
예제 #2
0
def solve():
    i = 1000
    while True:
        print i
        a, b, c, d = factor(i), factor(i + 1), factor(i + 2), factor(i + 3)
        if distinctFact(a,b) and distinctFact(a,c) and distinctFact(a,d) and distinctFact(b,c) \
        and distinctFact(b,d) and distinctFact(c,d):
            return i
        else:
            i += 1
예제 #3
0
파일: 542.py 프로젝트: acganesh/euler
def main():
    prev_val = False
    for i in range(2, 10000):
        max_val, max_ind = S2(i)
        if max_val != prev_val:
            print i, max_val, max_ind, factor(max_ind), is_square(max_ind)
        prev_val = max_val
예제 #4
0
def E70():
    res = 0
    min_res = 100
    min_i = 100
    p_set = []
    for i in range (3, MAXNUM, 2):
        if is_prime(i) == True:
            continue

        p_set = factor(i)
        if len(p_set) != 2:
            continue

        if int(p_set[0][1])!=1 or int(p_set[1][1])!=1:
            continue

        # [(421, 1), (571, 1)] <- both are 1
        cnt = i - (int(p_set[0][0])+int(p_set[1][0])-1)
        if is_perm(i, cnt) == False:
            continue

        res = float(i)/float(cnt)
        if min_res >= res:
            min_res = res
            min_i = i
            #print min_res, min_i, cnt, (1, p_set[0][0], p_set[1][0], i)

    print "result", min_res, min_i
    return 0
예제 #5
0
파일: twelve.py 프로젝트: PureSin/euler
def num_divisors(x):
    """returns the number of divisors of x"""
    l = factor(x)
    divisors = 1
    for exp in l:
        divisors *= exp[1]+1
    return divisors
예제 #6
0
def E70():
    res = 0
    min_res = 100
    min_i = 100
    p_set = []
    for i in range(3, MAXNUM, 2):
        if is_prime(i) == True:
            continue

        p_set = factor(i)
        if len(p_set) != 2:
            continue

        if int(p_set[0][1]) != 1 or int(p_set[1][1]) != 1:
            continue

        # [(421, 1), (571, 1)] <- both are 1
        cnt = i - (int(p_set[0][0]) + int(p_set[1][0]) - 1)
        if is_perm(i, cnt) == False:
            continue

        res = float(i) / float(cnt)
        if min_res >= res:
            min_res = res
            min_i = i
            #print min_res, min_i, cnt, (1, p_set[0][0], p_set[1][0], i)

    print "result", min_res, min_i
    return 0
예제 #7
0
def totient(n):
	F = factor(n)
	factors = zip(*F)[0]
	val = 1
	for num in factors:
		val *= (num-1)/float(num)
	val *= (n)
	return int(val)
예제 #8
0
 def brute_force(num_div):
     n = 1
     while True:
         factorization = factor(n)
         #print factorization
         num_factors = product([(x[1] + 1) for x in factorization])
         #print num_factors
         if num_factors == num_div:
             return num
         n += 1
예제 #9
0
def main(limit):
	num = 1
	vals = []
	while num < limit:
		val = 2*num**2-1
		vals.append(val)
		if not is_prime(val):
			print val, factor(val)
		num += 1
	return vals
예제 #10
0
def d(n):
    div_cache = cache[n]
    if div_cache != -1:
        return div_cache
    else:
        factorization = factor(n)
        div = 1
        for val in factorization:
            div *= (val[1] + 1)
        cache[n] = div
        return div
예제 #11
0
def D3(k):
    target = 20010
    prod = 1

    divisors = get_divisors(factor(k))

    for d in divisors:
        if is_prime(d+1):
            prod *= (d+1)
            if prod > target:
                return False

    return prod
예제 #12
0
파일: 545.py 프로젝트: acganesh/euler
def get_divisors(n):
    factors = factor(n)
    nfactors = len(factors)
    f = [0] * nfactors
    while True:
        yield reduce(lambda x, y: x * y,
                     [factors[x][0]**f[x] for x in range(nfactors)], 1)
        i = 0
        while True:
            f[i] += 1
            if f[i] <= factors[i][1]:
                break
            f[i] = 0
            i += 1
            if i >= nfactors:
                return
예제 #13
0
def rad(x):
    factors = factor(x)
    prod = 1
    for item in factors:
        prod *= item[0]
    return prod
예제 #14
0
<p>Find the first four consecutive integers to have four distinct prime factors. What is the first of these numbers?</p>
</div><br />
<br /></div>
"""
from Euler import is_prime

# best
from Euler import factor

ci = 1
nf = 4  # number of distinct factors
ns = 4  # number of consecutive integers
n = 2 * 3 * 5 * 7  # starting candidate for search
while ci != ns:
    n += 1
    if len(factor(n)) == nf:
        ci += 1
        print n, ci, nf, factor(n)
    else:
        ci = 0

print "Project Euler 47 Solution =", n - nf + 1

# slow
'''
ps = [ ]
i = 0
num = 1
while (i != 200):
    if (is_prime(num) == True):
        i+=1
예제 #15
0
def get_exps(n):
    return list(x[1] for x in factor(n))
예제 #16
0
</div><br />
<br /></div>
"""
from Euler import is_prime


# best
from Euler import factor

ci = 1
nf = 4      # number of distinct factors
ns = 4      # number of consecutive integers
n = 2*3*5*7 # starting candidate for search
while ci != ns:
    n += 1
    if len(factor(n)) == nf: 
        ci += 1 
        print n, ci, nf, factor(n)
    else: ci = 0

print "Project Euler 47 Solution =", n-nf + 1

# slow 
'''
ps = [ ]
i = 0
num = 1
while (i != 200):
    if (is_prime(num) == True):
        i+=1
        ps.append(num)
예제 #17
0
def sopf(p):
    sum=0
    for i in factor(p):
        sum+=i[0]
    return sum    
예제 #18
0
#!/usr/bin/python
#
# math from: http://en.wikipedia.org/wiki/Euler%27s_totient_function#Euler.27s_product_formula
#

from Euler import factor
from operator import mul

print '\nAnswer: {0}'.format(max([(reduce(mul, map(lambda p:1-1/float(p), map(lambda t: t[0], factor(n))))**-1, n) for n in range(2, 10**6+1)]))
예제 #19
0
def uniq_f(n):
  return [t[0] for t in factor(n)]