Exemplo n.º 1
0
def main():
    max_n = 0
    for a in range(-999, 1000):
        for b in range(-999, 1000):
            n = 0
            while is_prime(n**2 + a*n + b):
                n += 1
            if n > max_n:
                max_n = n
                max_ab = a*b
    return max_ab
Exemplo n.º 2
0
from __future__ import division
from sys import argv
import funcs

script, number = argv
number = int(number)

# for x in range(2,int(number/2)):
	# if(number/x % 1.0 == 0):
		# if(funcs.is_prime(x)):
			# print x
		
x = 2
		
while(not funcs.is_prime(number)):
	if(number/x % 1.0 == 0):
		print x
		number = int(number/x)
		x = 2
	else:
		x+=1
		
print number
Exemplo n.º 3
0
from __future__ import division
from sys import argv
import funcs

script, limit = argv
file = open('file.txt', 'w')
limit = int(limit)
total=0


for num in xrange(10,limit):
    if not funcs.is_prime(num):
        continue
    num_array = list(str(num))
    temp=num_array[:]
    trunc_left=False
    trunc_right=False
    
    #truncate from right
    while len(temp)>0:
        if not funcs.is_prime(int(''.join(temp))):
            break
        else:
            temp.pop()
    if len(temp)==0:
        trunc_right=True
        
    #truncate from left   
    temp=num_array[:]
    while len(temp)>0:
        if not funcs.is_prime(int(''.join(temp))):
Exemplo n.º 4
0
from __future__ import division
from sys import argv
import funcs

script, limit = argv
file = open('file.txt', 'w')
limit = int(limit)
total = 0

for num in xrange(2, limit):
    num = list(str(num))
    length = len(num)
    while funcs.is_prime(int(''.join(num))):
        temp = num.pop()
        num.insert(0, temp)
        length -= 1
        if length == 0:
            num = ''.join(num)
            file.write(num + '\n')
            total += 1
            break
print total
Exemplo n.º 5
0
from __future__ import division
from sys import argv
import funcs

script, number = argv
limit = int(number)
file=open('file.txt','w')
primes=[]
max_seq=[]
cur_max=0


for x in range(4000):
	if funcs.is_prime(x):
		primes.append(x)

for x in range(len(primes)):
    for y in range(x,len(primes)):
        file.write(str(x)+':'+str(y)+'\n')
        if funcs.is_prime(sum(primes[x:y])) and sum(primes[x:y])<limit:
			if cur_max<len(primes[x:y]):
				cur_max=len(primes[x:y])
				max_seq=primes[x:y]
				print sum(max_seq),cur_max,max_seq[0],max_seq[-1]
print '===='
print sum(max_seq),max_seq,len(max_seq)
Exemplo n.º 6
0
script, limit = argv
limit = int(limit)/100

    
percent=1
current_number=1
adder=0
prime_count=0
total_count=1

while percent>limit:
    adder+=2
    
    current_number=current_number+adder
    if funcs.is_prime(current_number):
        prime_count+=1

    current_number=current_number+adder
    if funcs.is_prime(current_number):
        prime_count+=1

    current_number=current_number+adder
    if funcs.is_prime(current_number):
        prime_count+=1
        
    current_number=current_number+adder
    
    total_count+=4
    percent=prime_count/total_count
    print prime_count,total_count
Exemplo n.º 7
0
from __future__ import division
from sys import argv
import funcs

# script, limit = argv
# limit=int(limit)
#file = open('file.txt','w')

"""
n=prime+2*a^2
"""
x=0
while 1:
    x+=1
    n=2*x+1
    if funcs.is_prime(n):
        print str(n)+':prime'
        continue
    a=1
    while not funcs.is_prime(n-2*a**2):
        a+=1
        if 2*a**2>n:
            print '***'
            print n
            quit()
    print n,a
    
Exemplo n.º 8
0
 def test_prime_4(self):
     isprime = funcs.is_prime(4)
     self.assertEqual(isprime, False)
Exemplo n.º 9
0
from __future__ import division
from sys import argv
import funcs

script, number = argv
limit = int(number)
total=0

for x in xrange(limit):
	if funcs.is_prime(x):
		print x
		total+=x
print '======'
print total
Exemplo n.º 10
0
from __future__ import division
from sys import argv
import funcs

script, limit = argv
file = open('file.txt', 'w')
limit = int(limit)
total = 0

for num in xrange(10, limit):
    if not funcs.is_prime(num):
        continue
    num_array = list(str(num))
    temp = num_array[:]
    trunc_left = False
    trunc_right = False

    #truncate from right
    while len(temp) > 0:
        if not funcs.is_prime(int(''.join(temp))):
            break
        else:
            temp.pop()
    if len(temp) == 0:
        trunc_right = True

    #truncate from left
    temp = num_array[:]
    while len(temp) > 0:
        if not funcs.is_prime(int(''.join(temp))):
            break
Exemplo n.º 11
0
from __future__ import division
from sys import argv
import funcs
import itertools 

script, limit = argv
limit=int(limit)+1

for n in [list(x) for x in list(itertools.permutations('7654321',7))]:
    if funcs.is_prime(int(''.join(n))):
        print int(''.join(n))
        break 
Exemplo n.º 12
0
from __future__ import division
from sys import argv
import funcs
import itertools

script, limit = argv
limit = int(limit) + 1

for n in [list(x) for x in list(itertools.permutations('7654321', 7))]:
    if funcs.is_prime(int(''.join(n))):
        print int(''.join(n))
        break
Exemplo n.º 13
0
from __future__ import division
from sys import argv
import funcs

# script, limit = argv
# limit=int(limit)
#file = open('file.txt','w')
"""
n=prime+2*a^2
"""
x = 0
while 1:
    x += 1
    n = 2 * x + 1
    if funcs.is_prime(n):
        print str(n) + ':prime'
        continue
    a = 1
    while not funcs.is_prime(n - 2 * a**2):
        a += 1
        if 2 * a**2 > n:
            print '***'
            print n
            quit()
    print n, a
Exemplo n.º 14
0
Arquivo: 027.py Projeto: qhool/pe
#!/usr/bin/env python
from funcs import is_prime

max_num = 0
for a in range(-999,1000):
    for b in range(-999,1000):
        n = 0
        while True:
            if not is_prime( n**2 + a * n + b ):
                break
            n += 1
        if n > max_num:
            print "n^2 + {0}n + {1} produces {2} primes. a*b = {3}".format(a,b,n,a*b)
            max_num = n
Exemplo n.º 15
0
from __future__ import division
from sys import argv
import funcs

script, num = argv
num = int(num)
cur_max=0
for a in range(-num,num):
	for b in range(-num,num):
		n=0
		while(funcs.is_prime(n*n+a*n+b)):
			n+=1
		if(n>cur_max):
			print n,a,b
			cur_max = n

Exemplo n.º 16
0
Arquivo: 051.py Projeto: qhool/pe
#!/usr/bin/env python
from math import log10, ceil
import funcs
import string

max_set = 0
for p in funcs.primes_generator():
    strp = str(p)
    #print strp
    for d in set( strp ):
        primeset = []
        digits = range(10)
        if strp[-1] == d:
            digits = range(1,10,2)
        for d2 in digits:
            if d == d2:
                continue
            p2 = string.replace( strp, d, str(d2) )
            if p2[0] == '0':
                continue
            p2 = int(p2)
            if funcs.is_prime( p2 ):
                primeset.append(p2)
        if len(primeset) > max_set:
            max_set = len(primeset)
            print "{0} {1} ---> {2}".format( max_set, p, primeset )
            if max_set >= 8:
                exit()
Exemplo n.º 17
0
 def test_prime_5(self):
     isprime = funcs.is_prime(5)
     self.assertEqual(isprime, True)
Exemplo n.º 18
0
from __future__ import division
from sys import argv
import funcs

script, num = argv
num = int(num)
cur_max = 0
for a in range(-num, num):
    for b in range(-num, num):
        n = 0
        while (funcs.is_prime(n * n + a * n + b)):
            n += 1
        if (n > cur_max):
            print n, a, b
            cur_max = n
Exemplo n.º 19
0
 def test_prime_10000(self):
     isprime = funcs.is_prime(10000)
     self.assertEqual(isprime, False)
Exemplo n.º 20
0
from __future__ import division
from sys import argv
import funcs

script, limit = argv
file = open('file.txt', 'w')
limit = int(limit)
total=0

for num in xrange(2,limit):
    num = list(str(num))
    length = len(num)
    while funcs.is_prime(int(''.join(num))):
            temp=num.pop()
            num.insert(0,temp)
            length-=1
            if length==0:
                num = ''.join(num)
                file.write(num+'\n')
                total+=1
                break
print total