def amount_of_circular_primes(lim): pl = Prime() pl.up_to(lim) circular_primes = pl.sequence[:4] for p in pl.sequence[4:-1]: if is_circular_prime(p, pl): circular_primes.append(p) return len(circular_primes)
def get_largest_pandigital_prime(): pl = Prime() combis = [] for n in xrange(2, 10): combis.extend(permutations(range(1, n + 1), n)) combis = map(lambda x: int(''.join(map(str, x))), combis) for n in combis[::-1]: if pl.is_prime(n): return n
def divisible_by_all_lower(max_divisor): """ Return the number that is divisible by all numbers lower than the max_divisor """ smallest = 1 pl = Prime() prime_divisors = pl.up_to(max_divisor) for p in prime_divisors: temp = p while temp <= max_divisor: temp *= p smallest *= p return smallest
def get_abundant_numbers(n): pl = Prime() abundant = [] for i in xrange(12, n): if i < proper_divisor_sum(i, pl): abundant.append(i) return abundant
def sum_of_amicable_numbers(n): pl = Prime() amicable_sum = 0 for i in xrange(2, n): divisor_sum = d(i, pl) if divisor_sum < i and divisor_sum > 0 and d(divisor_sum, pl) == i: amicable_sum += divisor_sum + i return amicable_sum
def sum_of_truncatable_primes(): pl = Prime() truncatable_primes = [] pl.up_to(10) while len(truncatable_primes) < 11: if is_truncatable_prime(pl.sequence[-1], pl): print pl.sequence[-1] truncatable_primes.append(pl.sequence[-1]) pl.find_next() return sum(truncatable_primes)
def find_prime(n): ps = Prime() return ps.up_to_element(n)[-1]
def first_triangle_divisors(n): tri = Triangle() pl = Prime() while get_amount_of_divisors(pl, tri.sequence[-1]) < n: tri.find_next() return tri.sequence[-1]
def sum_of_primes_up_to(n): pl = Prime() return sum(pl.up_to(n))
def largest_primefactor(n): ps = Prime() return ps.get_prime_factors(n)[-1]