Exemplo n.º 1
0
def find_perms():
	primes.init(10**7)
	big_primes = [p for p in reversed(primes.primes_list)]
	min = 10**7
	minval = 10**7
	start = cfn.binary_search(primes.primes_list,
			math.sqrt(10**7),
			len(primes.primes_list)-1,0)
	print start
	big_primes = [p for p in reversed(primes.primes_list[:start+1])]
	for p in big_primes:
		for bp in reversed(big_primes):
			if bp > p:
				break
			for bp2 in reversed(big_primes):
				if bp2 > bp:
					break
				print p,bp,bp2
				comp = int(p)*int(bp)*int(bp2)
				ep = int(p-1)*int(bp-1)*int(bp2-1)
				if comp/(ep*1.) >= minval:
					break
				if (cfn.digit_hash(comp)==cfn.digit_hash(ep) 
					and comp/(ep*1.) < minval):
					min = comp
					minval = comp/(ep*1.)
					print comp,p,bp,bp2,ep,comp/(ep*1.)
					break #biggest for this p
Exemplo n.º 2
0
def main(n):
	primes.init(10**6)
	nums = [1,3,7,9,13,27]
	offnums = [11,17,19,21,23]
	total = 0
	failure = False
	#below is the only intelligent part
	#look at each of the numbers modulo 5
	#and we can eliminate all possibilities for
	#n^2 except for n mod 5 = 0.
	for x in xrange(10,n,10):
		square = x*x
		if (((x % 3) not in (1,2)) 
			or ((x % 7) not in (3,4))):
			continue
		for offset in nums:
			if not primes.is_prime(square+offset):
				failure = True
				break
		if failure:
			failure = False
			continue
		for offset in offnums:
			if primes.is_prime(square+offset):
				failure = True
				break
		if not failure:
			print "Yay",x
			total += x
		failure = False
	print total
Exemplo n.º 3
0
def main():
	primes.init(10**6)
	sums = [0]*(10**6+1)
	for x in range(1,10**6):
		primes.factor(x)
		print x
	print x
Exemplo n.º 4
0
def find_all(max):
	result = []
	primes.init(max)
	for p in primes.primes_list:
		divides = is_prime_divider(int(p))
		if divides:
			result.append(p)
	return result
Exemplo n.º 5
0
def main():
	sol = []
	prime_length = 10**8
	pr.init(prime_length)
	primes = 1
	while sol == []:
		if primes > prime_length:
			pr.init(primes)
		sol = solutions(1200,5)
	print sol
	print "answer:",sum(sol)
Exemplo n.º 6
0
def main():
	primes.init(1000*1000+10)
	cur = 2
	total = 0
	while cur <= 1000*1000:
		total+= int(primes.euler_phi(cur))
		if cur % 1000 == 0: print cur
		if total < 0:
			print type(total),type(cur)
			break
		cur +=1
	print total
Exemplo n.º 7
0
def main():
	primes.init(10**7)
	pl = primes.primes_list
	start = bisect(pl,10**5)
	print start
	for n,p in enumerate(pl[start:]):
		p = int(p)
		p2 = p**2
		rem = (fmp(p-1,n+1+start,p2)+fmp(p+1,n+1+start,p2) )% p2 
		if rem > 10**10:
			break
	print p,rem,n+start+1
Exemplo n.º 8
0
def main(max):
	primes.init(2*max+1)
	k = 89
	results = []
	while len(results) <25:
		k+=2
		if k % 5 == 0:
			k+=2
		if primes.is_prime(k):
			continue
		small = smallest_k(k)
		if small and ((k-1) % small) == 0:
			print small
			results.append(k)
			print results
	print sum(results)
Exemplo n.º 9
0
def main(max):
	primes.init(2*max+1)
	#A(n) < n. Apparently, the pigeonhole principle can be pulled out
	#but I'm a bit confused as to how, as the number of states
	#the sum can be in is dependent not only on the current sum
	#but also the number of possible increments. Both of these 
	#potentially are n, so it seems the A(n) is only bounded by n^2.
	#for non-zero divisors, this can be immediately shown.
	k = 10**6-1
	small = None
	while small == None:
		k+=2
		if k % 5 == 0:
			k+=2
		small = smallest_k(k)
		if small < max:
			small = None
	print k
Exemplo n.º 10
0
#So, assuming we have an array with all primes less than 100 million
#(roughly 10 million I believe), how do we quickly find the reduced 
#multiples? I'm not going to bother actually. I'm just going to run
#through it. It'll be slow at first, but the difference between
#6th and the 7th smallest isn't that big, and we're just iterating
#through the array downwards, so the entire algorithm will be O(n)
#(roughly, not paying to much attention)

import math

import primes

def down_count(prime_array):
	total = 0
	index_left = 0
	index_right = len(prime_array)-1
	while index_left <= index_right: 
		if ((prime_array[index_left]*
		     prime_array[index_right]) <= 10**8):
			total += index_right-index_left+1
			print "total",total
			index_left +=1
		else:
			index_right -= 1
	return total

if __name__=="__main__":
	print "Beginning Count!"
	primes.init(10**8/2)
	print down_count(primes.primes_array)
Exemplo n.º 11
0
def main():
	primes.init(100)
	sum_fixed_n(10)
Exemplo n.º 12
0
	memo[special]= None
	result = None
	for prime in p.primes_list:
		count = 0
		if prime in special:
			continue
		for s in special:
			if p.is_prime(p.concat_nums(prime,s)):
				if p.is_prime(p.concat_nums(s,prime)):
					count +=1
		if count == len(special):
			result = special+(prime,)
			break
	if result == None:
		for i in range(len(special)):
			for prime in p.primes_list[1:]:
				if prime not in special:
					result = tryit(special[:i]+(prime,)
							+special[i+1:])
					if result:
						print result
						break
			if result:
				break
	memo[special] = result
	return memo[special]

if __name__=="__main__":
	p.init(1*10**4)
	print sum(tryit((3,7,109,673)))
Exemplo n.º 13
0
#sum of prime factors of 
#20*10**6, 15*10**6
import numpy as np
import primes

def somewhat_smaller_binom(n,k):
	z = np.arange(k,n+1)
	#for i in np.arange(2,(n-k)+1):
	z[:-2] /= np.arange(2,(n-k)+1)
	
	map(primes.factor,z)

primes.init(10**7)
print somewhat_smaller_binom(20*10**6,15*10**6)
Exemplo n.º 14
0
import primes
import itertools as it
import sys

def spiral(n):
	sum = 1
	for side in range(2,n,2):
		for corner in range(4):
			sum += side
			yield sum,side+1

def prime_percent(n):
	prime_count = 0
	percent = 1
	for i,(s,side) in it.izip(it.count(2),spiral(n)):
		if primes.is_prime(s):
			prime_count += 1
			percent = (prime_count*1.0)/i
		percent = (prime_count*1.0)/i
		if percent < .1:
				#print i,percent,side
				print side
				break

if __name__=="__main__":
	primes.init(10**6)
	n = 10**6
	if len(sys.argv) > 1:
		n = eval(sys.argv[1])
	prime_percent(n)
Exemplo n.º 15
0
    return p


def pyramid_enumerate(n, options, f):
    result = []
    index = 0
    for i in range(n):
        while f(result + [options[index]]) < f(result + [options[index + 1]]):
            print index
            index += 1
        result.append(options[index])
        index = 0
    return result


def combinations_distinct(alist):
    total = 0
    for x in range(1, len(alist) + 1):
        total += choose_degen(alist, x) * 2 ** (x - 1)
    return total + 1


primes.init(1000)

nums = [2 * 3 * 2 * 3 * 5 * 5]
for x in nums:
    res = reciprocals(x)
    print res, map(lambda x: Frac(x[1]) / Frac(x[0]), res)
    print len(res), x
    print combinations_distinct([(2, 2), (3, 2), (5, 2)])
Exemplo n.º 16
0
def main():
	primes.init(50*10**6)
	print number_of_ways(50*10**6)
Exemplo n.º 17
0
def main():
	primes.init(10**7)
	brute_force()
Exemplo n.º 18
0
import primes

primes.init(10**4)
for x in range(2,10**4):
	primes.factor(x)
Exemplo n.º 19
0
def main():
    primes.init(1000)
    print "hi"
    enumerate_min(4 * 10 ** 6)