Example #1
0
def check_consecutive_numbers_having_distinct_prime_factors(start, n):
    for i in xrange(start, start+n):
        distinct_pf = set()
        pf = prime_factors(i)
        for p in pf:
            distinct_pf.add(p)
        if len(distinct_pf) != n:
            return False
    return True
Example #2
0
def count_divisors(n):
    pfs = prime_factors(n)
    size = max(pfs)
    factor_count = [0] * (size+1)
    for i in pfs:
        factor_count[i] += 1
    count = 1
    for i in factor_count:
        if i > 0:
            count *= (i + 1)
    return count
Example #3
0
def eul88(num):
	found_lengths = []
	found_values = []
	solution = []
	for i in range(4,num*2):
		used = False
		factors = util.prime_factors(i)
		factor_sets = util.recuse_over_factors(factors,[[]])
		lengths = map(lambda x:util.solve_length_for_numbers(x),factor_sets)
		for length in lengths:
			if not length in found_lengths and length <= 12000:
				found_lengths.append(length)
				solution.append([length,i])
				if len(found_lengths) == 12000:
					break
				if not used:
					found_values.append(i)
					used = True
		print i,used

	return solution,found_values
Example #4
0
def main():
    # The period of a repeating decimal is the multiplicative order of 10
    # modulo the denominator, i.e. the lowest number k such that 10**k = 1
    # modulo the denominator.
    # Note that if the prime decomposition of n consists only of 2 and 5, it
    # will be a terminating decimal and can be immediately excluded.
    # Additionally, the period of the repeating decimal is always less than the
    # denominator.

    max_period = 0
    answer = 0

    for n in range(2, 1000):
        if all(x == 2 or x == 5 for x in prime_factors(n)):
            continue

        for k in range(1, n):
            if (10**k) % n == 1:
                if k > max_period:
                    answer = n
                    max_period = k
                break

    print(answer)
Example #5
0
def solution():
    N = 600851475143
    pfs = prime_factors(N)
    result = pfs[-1]
    return result
def totient(n):
    pf = set(util.prime_factors(n))
    return n - 1 + sum([(-1)**i * ((n - 1) / reduce(lambda x, y: x * y, comb))
                        for i in range(1,
                                       len(pf) + 1)
                        for comb in itertools.combinations(pf, i)])
Example #7
0
def phi(n):
    r = 1.0
    for p in prime_factors(n):
        r *= 1.0 - 1.0 / float(p)
    r *= n
    return r
Example #8
0
def main():
    print(max(prime_factors(600851475143)))
Example #9
0
def bruteForce():
    startTime = time.time()
    N = 10000000

    minResult = N
    index = 0
    roundStartTime = time.time()
    for i in range(2, N):
        if i % 100000 == 0: 
            print('{0} done, this round takes {1} seconds, elapsed {2} seconds'.format(i, time.time()-roundStartTime, time.time()-startTime))
            roundStartTime = time.time()
        phi_i = phi(i)
        current = float(i) / float(phi(i))
        if isPermutation(i, phi_i) and current < minResult: 
            minResult = current
            index = i
            print('found {}, phi_i: {}, min: {}, prime factors: {}'.format(i, phi_i, minResult, prime_factors(i)))

    return index
Example #10
0
def phi(n):
    r = 1.0
    for p in prime_factors(n):
        r *= (1.0 - 1.0/float(p))
    r *= n
    return int(round(r))
Example #11
0
def main():
    print max(prime_factors(600851475143))
Example #12
0
def square_free(x):
    return len(prime_factors(x)) == len(unique_prime_factors(x))
Example #13
0
def problem_3(n):
	return max(prime_factors(n))
Example #14
0
def largest_prime_factor(n):
    return max(util.prime_factors(n))
Example #15
0
File: 047.py Project: jag426/euler
from itertools import count
from util import prime_factors

for n in count(2*3*5*7):
    if all(map(lambda i: len(prime_factors(n+i)) == 4, range(4))):
        print(n)
        break