Exemplo n.º 1
0
def main():
    prime = Prime()
    prime_list = []
    prime_under_one_million = []
    for p in prime.get_prime():
        if p < 1000:
            prime_list.append(p)
            prime_under_one_million.append(p)
        elif p < 1000000:
            prime_under_one_million.append(p)
        else:
            break

    negative_prime_list = [0 - v for v in sorted(prime_list, reverse=True)]
    negative_prime_list.extend(prime_list)

    # b is try to be big, then n&b co efficient will be big
    # a is try to be small, then
    current_max_combination = 0
    for a in negative_prime_list:
        for b in negative_prime_list:
            combi_cnt = 0
            for n in count():
                if n * n + a * n + b not in prime_under_one_million:
                    break
                else:
                    combi_cnt += 1
            if combi_cnt > current_max_combination:
                print 'find an greater combination: a={}, b={} has {} combinations'.format(
                    a, b, combi_cnt)
                current_max_combination = max(current_max_combination,
                                              combi_cnt)
Exemplo n.º 2
0
def ans():
    for prime in Prime.gen_nums():
        if prime < 120000:
            continue

        # Replace all combinations of digits
        list_ = list(str(prime))
        length = len(list_)
        for count in range(length):
            combs = combinations(range(length), count)
            for indices in combs:

                # Count the number of primes by replacing
                # the selected digits with some other digit
                generated_primes = set()
                for replacement in range(10):
                    copy = list_.copy()
                    for i in indices:
                        copy[i] = str(replacement)
                    number = int(''.join(copy))
                    if Prime.contains(number):
                        generated_primes.add(number)

                if 7 < len(generated_primes):
                    return min(generated_primes)
Exemplo n.º 3
0
def Prime_div(num,Prime,divisors):
    """ Recursively Finds the prime divisors of a given number,

    Args:
        num (int): Number whose Prive divisors will be calculated
        Prime (Prime) : An instance of the Prime class used to generate primes
        divisors (list): A list representing the divisors found so far        
    
    """
    if divisors == []: #if this is the first call add one to list all numbers div by 1
        divisors.append(1)
    
    if Prime.isPrime(num):#base case. when prime number is found we have found all Prime divisors
        temp = divisors        
        divisors.append(num)
        
        
        return divisors
    else:# testing case. If we have not found our base prime, then we keep calling the function
        Prime.reset()
        factor = Prime.nextPrime()
        found = False#Set to false in each call 
        while factor < num/2 and not found:
            if num%factor == 0:
                divisors.append(factor)#Appends a found prime divisor to our list
                found = True
            if not found:
                factor = Prime.nextPrime()#Cycles through prime list until we find a prime the number is divisible by
        return Prime_div(num/factor,Prime,divisors)
Exemplo n.º 4
0
def main():
    P = Prime()
    tn_iterator = get_triangle_number()
    while True:
        triangle_number = tn_iterator.next()
        count_of_divisors = P.get_count_of_divisors_by_number(triangle_number)
        if 500 < count_of_divisors:
            break
    print triangle_number
Exemplo n.º 5
0
def is_truncatable(n):
    str_n = str(n)
    if len(str_n) < 2:
        return False
    for i in range(1, len(str(n))):
        if not Prime.contains(int(str_n[:i])):
            return False
        if not Prime.contains(int(str_n[i:])):
            return False
    return True
Exemplo n.º 6
0
def ans():
    size = 5
    skip_to = 8300
    for p in Prime.gen_nums():
        if p < skip_to:
            continue
        nums = [q for q in Prime.gen_nums(p) if compatible(q, p)]
        for tuple_ in combinations(nums, size - 1):
            if remarkable(tuple_):
                return p + sum(tuple_)
Exemplo n.º 7
0
def ans():
    prime_list = list(Prime.gen_nums(4000))
    longest = (0, 0)
    for i in range(len(prime_list)):
        sum_ = 0
        for j in range(i, len(prime_list)):
            sum_ += prime_list[j]
            if 1000000 <= sum_:
                break
            if Prime.contains(sum_) and longest[1] < j - i + 1:
                longest = (sum_, j - i + 1)
    return longest[0]
Exemplo n.º 8
0
class PrimeTest(unittest.TestCase):

    # set up variables that we will use globally
    def setUp(self):
        self.prime = Prime()

    def test_invalid_input(self):
        result = self.prime.primeNumbers("string")
        self.assertEqual(result, 'Input value should be an Integer',
                         'Input allows invalid input')

    def test_that_input_should_be_greater_than_1(self):
        result = self.prime.primeNumbers(1)
        self.assertEqual(result, 'Input should be a number greater than 1',
                         'Input allows incorrect values')

    def test_that_float_inputs_are_rounded_to_next_whole_number(self):
        result = self.prime.primeNumbers(36.7)
        self.assertEqual(result, [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37],
                         'Floats give incorrect output')

    def test_function_gives_correct_output_with_2(self):
        result = self.prime.primeNumbers(2)
        self.assertEqual(result, [2], 'Incorrect output')

    def test_function_gives_correct_output_with_3(self):
        result = self.prime.primeNumbers(3)
        self.assertEqual(result, [2, 3], 'Incorrect output')

    def test_function_gives_correct_output_with_15(self):
        result = self.prime.primeNumbers(15)
        self.assertEqual(result, [2, 3, 5, 7, 11, 13], 'Incorrect output')

    def test_function_gives_correct_output_with_60(self):
        result = self.prime.primeNumbers(60)
        self.assertEqual(
            result,
            [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59],
            'Incorrect output')

    def test_function_gives_correct_output_with_20(self):
        result = self.prime.primeNumbers(20)
        self.assertEqual(result, [2, 3, 5, 7, 11, 13, 17, 19],
                         'Incorrect output')

    def test_function_gives_correct_output_with_10(self):
        result = self.prime.primeNumbers(10)
        self.assertEqual(result, [2, 3, 5, 7], 'Incorrect output')

    def test_function_gives_correct_output_with_float(self):
        result = self.prime.primeNumbers(18.6)
        self.assertEqual(result, [2, 3, 5, 7, 11, 13, 17, 19],
                         'Incorrect output')
Exemplo n.º 9
0
def ans():
    circular_primes = set([2])
    for p in Prime.gen_nums(1000000):
        if any(x in str(p) for x in '02468'):
            continue
        is_circular = True
        for i in range(len(str(p))):
            if not Prime.contains(int(str(p)[i:] + str(p)[:i])):
                is_circular = False
                break
        if is_circular:
            circular_primes.add(p)
    return len(circular_primes)
Exemplo n.º 10
0
def ans():
    num = 9
    while satisfies_conjecture(num):
        num += 2
        while Prime.contains(num):
            num += 2
    return num
Exemplo n.º 11
0
def satisfies_conjecture(n):
    root = 1
    while 2 * root**2 < n:
        if Prime.contains(n - 2 * root**2):
            return True
        root += 1
    return False
Exemplo n.º 12
0
 def test_get_prime(self):
     self.assertEqual(Prime.get_prime(0), 2)
     self.assertEqual(Prime.get_prime(1), 3)
     self.assertEqual(Prime.get_prime(2), 5)
     self.assertEqual(Prime.get_prime(3), 7)
     self.assertEqual(Prime.get_prime(4), 11)
     self.assertEqual(Prime.get_prime(5), 13)
     self.assertEqual(Prime.get_prime(6), 17)
     self.assertEqual(Prime.get_prime(7), 19)
Exemplo n.º 13
0
def ans():
    n = 1
    for p in Prime.gen_nums():
        next_ = n * p
        if 1000000 < next_:
            return n
        n = next_
    return n
Exemplo n.º 14
0
def ans():
    truncatable = set()
    for p in Prime.gen_nums():
        if is_truncatable(p):
            truncatable.add(p)
        if len(truncatable) == 11:
            break
    return sum(truncatable)
Exemplo n.º 15
0
def main(min_prime, max_prime):
    """Parse the args and if all is good, summon Prime to do the computation."""
    logger.debug('Inside main()')
    print('Calculating prime numbers between {} and {}'.format(
        min_prime, max_prime))
    primes = Prime().primes_between(start=min_prime, stop=max_prime)
    print('Found {} prime numbers'.format(len(primes)))
    print(primes)
Exemplo n.º 16
0
def nextprime(np):

    if (np <= 1):
        return 2

    prime = np
    found = False

    if (Prime(prime) == True):
        return np

    while (not found):
        prime += 1

        if (Prime(prime) == True):
            found = True

    return prime
Exemplo n.º 17
0
def get_prime_factors(n):
    """ Returns the counts of each prime factor of n
    """
    if n < 1:
        raise ValueError
    if n == 1:
        return Counter()
    divisor = 2
    while n % divisor != 0:
        divisor = Prime.after(divisor)
    return Counter({divisor: 1}) + get_prime_factors(n // divisor)
Exemplo n.º 18
0
def ans():
    lim = 1000
    largest = (None, None, 0)
    for a in range(-lim + 1, lim):
        for b in range(-lim, lim + 1):
            n = 0
            while Prime.contains(f(n, a, b)):
                n += 1
            if largest[2] < n:
                largest = (a, b, n)
    return largest[0] * largest[1]
Exemplo n.º 19
0
def ans():
    groups = defaultdict(set)
    for prime in Prime.gen_nums(10000):
        groups[''.join(sorted(str(prime)))].add(prime)
    for set_ in groups.values():
        for comb in combinations(set_, 3):
            seq = sorted(list(comb))
            if seq[0] < 1000:
                continue
            if (seq[2] + seq[0] == 2 * seq[1] and seq[0] != 1487):
                return ''.join(str(n) for n in seq)
Exemplo n.º 20
0
class TestPrime(object):
    """Tests focused on the Prime class."""
    def setup_method(self):
        self.prime = Prime()

    def test_prime_happy(self):
        """Test prime() method on the happy path."""
        result = self.prime.primes()
        assert result is not None
        assert True

    def test_prime_5(self):
        """ Test prime(5) and make sure it returns [2, 3, 5]. """
        result = self.prime.primes(stop=5)
        assert len(result) == 3, 'list of primes was expected to have length 3'
        assert result[0] == 2
        assert result[1] == 3
        assert result[2] == 5

    def test_is_prime(self):
        assert self.prime.is_prime(5)
        assert self.prime.is_prime(7)

        assert not self.prime.is_prime(500)
        assert not self.prime.is_prime(280000)

    def test_primes(self):
        result = self.prime.primes(stop=100000)
        print(result)

    def test_primes_between(self):
        result = self.prime.primes_between(1, 5)

        expected_result = [2, 3]
        assert result == expected_result, 'Expected list of primes did not match'

        expected_result = [
            7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
            73, 79, 83, 89
        ]
        result = self.prime.primes_between(5, 97)
        assert result == expected_result, 'Expected list of primes did not match'

        # When min and max yield an empty set, we should get an empty list
        result = self.prime.primes_between(4, 5)
        assert result == [], 'Result should have been an empty list'
Exemplo n.º 21
0
def main():
    prime_ins = Prime()
    prime_hash = dict()
    circular_prime_list = list()
    for i in prime_ins.get_prime():
        if i < TARGET:
            prime_hash[i] = True
        else:
            break

    for prime in prime_hash:
        circular_list = []
        for i in range(1, len(str(prime))):
            circular_list.append(int(''.join(str(prime)[i:] + str(prime)[0:i])))
        for num in circular_list:
            if not num in prime_hash:
                break
        else:
            print "circular prime found: {}".format(prime)
            circular_prime_list.append(prime)

    print "count of all circular prime is {}".format(len(circular_prime_list))
Exemplo n.º 22
0
def ans():
    divisors = list(Prime.gen_nums(18))
    sum_ = 0
    for p in gen_pandigitals(from_=0, to=9):
        has_property = True
        for i in range(1, 8):
            dividend = int(str(p)[i:i + 3])
            if dividend % divisors[i - 1] != 0:
                has_property = False
                break
        if has_property:
            sum_ += p
    return sum_
Exemplo n.º 23
0
 def test_get_greatest_common_divisor(self):
     self.assertEqual(
         Prime.get_greatest_common_divisor(3 * 5 * 7 * 7 * 11,
                                           5 * 7 * 11 * 11 * 13),
         5 * 7 * 11)
     self.assertEqual(Prime.get_greatest_common_divisor(1, 2), 1)
     self.assertEqual(Prime.get_greatest_common_divisor(-1, 2), 1)
     self.assertEqual(Prime.get_greatest_common_divisor(-1, -2), 1)
     self.assertEqual(Prime.get_greatest_common_divisor(2, -1), 1)
     self.assertEqual(Prime.get_greatest_common_divisor(-2, 1), 1)
     self.assertEqual(Prime.get_greatest_common_divisor(-2, -1), 1)
Exemplo n.º 24
0
 def test_get_prime_factors(self):
     self.assertRaises(ValueError, lambda: Prime.get_prime_factors(1))
     self.assertRaises(ValueError, lambda: Prime.get_prime_factors(0))
     self.assertRaises(ValueError, lambda: Prime.get_prime_factors(-1))
     self.assertRaises(ValueError, lambda: Prime.get_prime_factors(-3))
     self.assertListEqual(Prime.get_prime_factors(2), [2])
     self.assertListEqual(Prime.get_prime_factors(2 * 3 * 5 * 7 * 7 * 11),
                          [2, 3, 5, 7, 7, 11])
Exemplo n.º 25
0
class TestPrime(unittest.TestCase):
    def setUp(self):
        self.prime = Prime()

    def test_prime_returns_error_if_arg_is_not_positive_integer(self):
        self.assertRaises(TypeError, self.prime.prime, -10)

    def test_prime_returns_error_message_if_arg_is_string(self):
        self.assertRaises(TypeError, self.prime.prime, '10')

    def test_prime_returns_error_message_if_arg_is_float(self):
        self.assertRaises(TypeError, self.prime.prime, 10.0)

    def test_prime_returns_empty_list_when_arg_is_0(self):
        result = self.prime.prime(0)
        self.assertEqual([], result)

    def test_prime_returns_2_when_arg_is_2(self):
        result = self.prime.prime(2)
        self.assertEqual(2, result)

    if __name__ == '--main--':
        unittest.main()
Exemplo n.º 26
0
def ans():
    diags = gen_diagonals()
    next(diags)
    i = 1
    prime_count = 0
    total_count = 1
    while True:
        for n in next(diags):
            if Prime.contains(n):
                prime_count += 1
            total_count += 1
        i += 2
        if prime_count / total_count < .1:
            break
    return i
Exemplo n.º 27
0
def ans():
    # The insight is that n / phi(n) is minimized when n has a few, large prime
    # factors (n can't be prime, since prime numbers don't satisfy the
    # permutation criteria). Also, note that we don't actually have to compute
    # all of the numbers coprime with n to determine phi(n); instead we can use
    # the fact that n is a product of two primes to calculate phi(n) in
    # constant time.
    min_n = None
    min_value = None
    primes = Prime.gen_nums(10**4)
    combos = combinations(primes, 2)
    for one, two in list(combos):
        n = one * two
        if 10**7 <= n:
            continue
        num_coprimes = one * two - one - two + 1
        if sorted(str(n)) == sorted(str(num_coprimes)):
            value = n / num_coprimes
            if not min_value or value < min_value:
                min_n = n
                min_value = value
    return min_n
Exemplo n.º 28
0
#!/usr/bin/python
#
# Author: Ryan Scott
# Purpose: Solve problem 007 of the Euler Project
# Assumes: Python 2.7
#
# By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
# What is the 10 001st prime number?

from prime import Prime

prime = Prime()
prime_count = 6 # given by problem
num = 14        # next number to try
while True:
    if prime.is_prime(num):
        prime_count += 1
    if 10001 == prime_count:
        break
    num += 1

print str(num - 1)
Exemplo n.º 29
0
#!/usr/bin/python
import math
from math import *
import itertools
import decimal
from decimal import *
from collections import deque
from prime import Prime

p = Prime()
L = p.factorize(644)
print L

for i in range(100000,150000):
	fac1=len(sorted(set(p.factorize(i))))
	if(fac1==4):
		fac2=len(sorted(set((p.factorize(i-1)))))
		if(fac2==4):
			fac3=len(sorted(set((p.factorize(i-2)))))
			if(fac3==4):
				fac4=len(sorted(set((p.factorize(i-3)))))
				if(fac4==4):
					print i,i-1,i-2,i-3
					print p.factorize(i)
					print p.factorize(i-1)
					print p.factorize(i-2)
					print p.factorize(i-3)		
					break
Exemplo n.º 30
0
		return True
	else:
		return False
		
def divisors(n):
	div=[]
	for i in range (2,int(math.sqrt(n))+1):
		if(n%i==0):
			if(n/i != i):
				div.append(i)
				div.append(n/i)
			else:
				div.append(i)
	return div

p = Prime()	
primes=[]
nfn=[]	
def ffn(n):
	if p.factor(n)==None:
		return (n/((n-1)*1.0),n-1,n,0,[])
	else:
		div=divisors(n)
		f=n
		j=0
		factors=[]
		for d in div:
			if p.factor(d)==None:
				f=f/d
				f*=(d-1)
				factors.append(d)
Exemplo n.º 31
0
#!/usr/bin/python
import math
from math import *
import itertools
import decimal
from decimal import *
from collections import deque
from prime import Prime
import operator
import string
from sets import Set

p = Prime()
primes=[]
j=0
for i in range(2,2000):
	if(p.factor(i)==None):
		primes.append(i)
		if i==4159:
			print j
		j+=1	

def removeFromList(n,l):
	lis=[]
	for iL in range(0,len(l)):
			if(n == l[iL]):
				lis=l[:iL]+l[iL+1:]
	return lis	

def checkNums(n1,n2):
Exemplo n.º 32
0
from prime import Prime

p = Prime()
f = p.factor(45)
L = p.factorize(45)

print f,L
Exemplo n.º 33
0
#!/usr/bin/python
import math
from math import *
import itertools
import decimal
from decimal import *
from collections import deque
from prime import Prime
import operator
import string
from sets import Set

p = Prime()
primes=[]
j=0
for i in range(2,2000):
	if(p.factor(i)==None):
		primes.append(i)
		if i==4159:
			print j
		j+=1	

def removeFromList(n,l):
	lis=[]
	for iL in range(0,len(l)):
			if(n == l[iL]):
				lis=l[:iL]+l[iL+1:]
	return lis	

def checkNums(n1,n2):
	str1=str(n1)
Exemplo n.º 34
0
#!/usr/bin/python
import math
from math import *
import itertools
import decimal
from decimal import *
from collections import deque
from prime import Prime

p = Prime()
num=1
sumtotal=1
diagonals=[]
diagPrimes=[]
for x in range(1,15000):
	for y in range(1,5):
		num=num+2*x
		diagonals.append(num)
		if p.factor(num)==None:
			diagPrimes.append(num)
	if(len(diagPrimes)*(1.0)/(len(diagonals)+1)*(1.0))<0.10:
		print num**0.5
		break
##The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove ##
##digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7.##
## Similarly we can work from right to left: 3797, 379, 37, and 3. ##

## Find the sum of the only eleven primes that are both truncatable from ##
##left to right and right to left. ##

## NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes. ##


from prime import Prime
p = Prime()
def truncatableprime(n):
    ## from left to right ##
    for i in range(len(str(n))):
        if not p.isprime(int(str(n)[i:])):
            return False
    ## from right to left             
    tmp = n
    while tmp>0:
        if not p.isprime(tmp):
            return False
        tmp = tmp/10

    return True


count = 1

n = 10
sumofTP = 0
Exemplo n.º 36
0
def main():
    P = Prime()
    prime_factors = P.get_prime_factors_by_number(600851475143)
    print(max(prime_factors.keys()))
Exemplo n.º 37
0
class Divisor:
    def __init__(self,):
        self.__mod_prime = Prime()
        self.__mod_permutation = Permutation()

    def get_count_of_divisors(self, n):
        """
        >>> D = Divisor()
        >>> D.get_count_of_divisors(2)
        2

        >>> D.get_count_of_divisors(100)
        9

        >>> D.get_count_of_divisors(-1)
        Traceback (most recent call last):
        ValueError: input has to be a positive int or long: -1
        """
        if isinstance(n, (int, long)) == False or n <= 0:
            raise ValueError("input has to be a positive int or long: %s" %n)
        if n == 1:
            return 1
        # n = (a ** p) * (b ** q) * (c ** r) のとき、
        # n の約数は (p + 1) * (q + 1) * (r + 1) で求められる
        factors = self.__mod_prime.get_prime_factors(n)
        powers = [v + 1 for v in factors.values()] # [p+1, q+1, r+1, ...]
        return reduce(lambda x, y: x * y, powers)

    def get_proper_divisors(self, n, n_large = 2000):
        """
        >>> D = Divisor()
        >>> D.get_proper_divisors(28)
        [1, 2, 4, 7, 14]

        >>> D.get_proper_divisors(200)
        [1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100]
        """
        if n >= n_large:
            return self._get_pds1(n)
        else:
            return self._get_pds2(n)

    def _get_pds1(self, n):
        prime_factors = self.__mod_prime.get_prime_factors(n)

        # prime_all_powers
        prime_all_powers = {}
        # for n=600 primes = [2, 3, 5]
        for prime,power in prime_factors.items(): # for n=200 prime=2,5
            prime_all_powers[prime] = [prime * pw for pw in range(power)]
        # for n=600 prime_all_powers = {2:[1,2,4,8], 3:[1,3], 5:[1,5,25]}

        res = []
        for pair in self.__mod_permutation.get_all_permutations(prime_all_powers.values()):
            # pairs: [1,1,1], [1,1,5], [1,1,25], [1,3,1], [1,3,5], [1,3,25], .... [8,3,25]
            res.append( reduce(lambda x,y: int(x)*int(y), pair) )
        return res

    def _get_pds2(self, n):
        pds = []
        for i in range(1, int(n / 2) + 1):
            if n % i == 0:
                pds.append( i )
        return pds
Exemplo n.º 38
0
 def __init__(self,):
     self.__mod_prime = Prime()
     self.__mod_permutation = Permutation()
Exemplo n.º 39
0
from math import *
import itertools
import decimal
from decimal import *
from collections import deque
from prime import Prime

def tupleToStr(t):
	i=0
	s=""
	while(i<len(t)):
		s+=str(t[i])
		i+=1
	return s
	
p = Prime()
L = p.factorize(644)

print tupleToStr(list(itertools.permutations("1234"))[0])

def isPerm(n1,n2,n3):
	permsN1=list(itertools.permutations(str(n1)))
	size=len(permsN1)
	perms=[]
	for i in range(0,size):
		perms.append(int(tupleToStr(permsN1[i])))
	if(n2 in perms and n3 in perms):
		print n1,n2,n3
		
isPerm(1487,4817,8147)
Exemplo n.º 40
0
    def test_prime(self):
        """."""

        self.assertEqual(bool(Prime(7)), True)
        self.assertEqual(bool(Prime(6)), False)
Exemplo n.º 41
0
from prime import Prime
import itertools
import sys

p  = Pandigital()
result = None
numbers = '987654321'
for n in range(0,6):
	number = numbers[n:]
	for perm in itertools.permutations(number, len(number)):
		candidate = int(''.join(perm))
		if Prime.isprime(int(candidate)):
			result = candidate
			break
	if (result != None):
		break
print result
Exemplo n.º 42
0
import operator
import string
from sets import Set

def divisors(n):
	div=[]
	for i in range (2,int(math.sqrt(n))+1):
		if(n%i==0):
			if(n/i != i):
				div.append(i)
				div.append(n/i)
			else:
				div.append(i)
	return div

p = Prime()
primes=[]
nfn=[]	
for n in range(2,1000001):
	if p.factor(n)==None:
		nfn.append((n/((n-1)*1.0),n))
	else:
		div=divisors(n)
		f=n
		for d in div:
			if p.factor(d)==None:
				f=f/d
				f*=(d-1)
		nfn.append((n/(f*1.0),n))

print max(nfn)
Exemplo n.º 43
0
#!/usr/bin/python
import math
from math import *
import itertools
import decimal
from decimal import *
from collections import deque
from prime import Prime
	
p = Prime()
L = p.factorize(644)

primes=[]
for i in range(2,10000):
	if p.factor(i)==None:
		primes.append(i)

sum=0
i=0
j=0
for j in range(0,60):
	max=600	
	while(max>0):
		i=j
		while(i<max+j):
			sum+=primes[i]
			i+=1
		if(p.factor(sum)==None and sum>900000 and sum<1000000):
			print sum,i-1-j
		max-=1			
		sum=0		
Exemplo n.º 44
0
def main():
    P = Prime()
    primes = P.get_primes_by_index(10001)
    print primes[-1]
Exemplo n.º 45
0
def ans():
    num = 600851475143
    end = int(sqrt(num)) + 1
    for i in reversed(range(2, end)):
        if num % i == 0 and Prime.contains(i):
            return i
Exemplo n.º 46
0
import sys
import copy
import math
from collections import deque
from prime import Prime
prime_man = Prime()

#obtain the name of the input
def fileName():
    filename = 'input'
    if len(sys.argv) > 1:
        filename = sys.argv[1]
    else:
        print("File was not indicated")
        exit()
    return filename

fn = fileName()
file = open(fn, 'r')
out = open('output', 'w')

line_number = 1;
testcase = 1
max_testcases = 0
tc_ln = 0

while True:
    line = file.readline()
    if line:
        line = line.replace("\n","")
        inputs = line.split(" ")
Exemplo n.º 47
0
from prime import Prime

longest = 0
ans = 0
Prime.isPrime(1000000)
for i in range(0, len(Prime.p)):
    curr = 0
    value = 0
    for j in range(i, len(Prime.p)):
        curr += 1
        value += Prime.p[j]
        if value > 1000000:
            break
        if Prime.isPrime(value) and curr > longest:
            longest = curr
            ans = value
    if longest >= curr:
        break

print(ans)
Exemplo n.º 48
0
#!/usr/bin/python
#
# Author: Ryan Scott
# Purpose: Solve problem 003 of the Euler Project
# Assumes: Python 2.7
#
# The prime factors of 13195 are 5, 7, 13 and 29.
# What is the largest prime factor of the number 600851475143 ?

from prime import Prime
import math

num = 600851475143

# keep track of state through loop
largest_prime_divisor = 0
prime = Prime()
for possible_divisor in range(2, int(math.ceil(math.sqrt(num)))):
    if 0 == num % possible_divisor and prime.is_prime(possible_divisor):
        if possible_divisor > largest_prime_divisor:
            largest_prime_divisor = possible_divisor

print str(largest_prime_divisor)
Exemplo n.º 49
0
from prime import Prime

target = int(5e7)
mask = [1] * target
ans = 0

for i in map(lambda x: x**2, Prime.prime()):
    if i >= target:
        break
    for j in map(lambda x: x**3, Prime.prime()):
        if i + j >= target:
            break
        for k in map(lambda x: x**4, Prime.prime()):
            s = i + j + k
            if s >= target:
                break
            ans += mask[s]
            mask[s] = 0

print(ans)
Exemplo n.º 50
0
Arquivo: 010.py Projeto: m-a-t-h/peppy
def main():
    P = Prime()
    print sum(P.get_primes_by_upper_limit(2000000))
Exemplo n.º 51
0
def main():
    P = Prime()
    print sum(P.get_primes_by_limit_number(2000000))