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
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
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))):
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
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)
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
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
def test_prime_4(self): isprime = funcs.is_prime(4) self.assertEqual(isprime, False)
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
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
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
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
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
#!/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
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
#!/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()
def test_prime_5(self): isprime = funcs.is_prime(5) self.assertEqual(isprime, True)
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
def test_prime_10000(self): isprime = funcs.is_prime(10000) self.assertEqual(isprime, False)
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