Esempio n. 1
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
Esempio n. 2
0
def brute_force():
	cands = range(10**6,10**7)
	for i,x in enumerate(cands):
		ep = primes.euler_phi(x)
		cands[i] = x,ep,x/(1.*ep)
	print "eulerphi computed"
	cands.sort(key=lambda x:x[2])
	print "sorted"
	for cand in cands:
		if cfn.digit_hash(cand[0])==cfn.digit_hash(cand[1]):
			print cand
			break
Esempio n. 3
0
def hyperexponent_mod(n,k,mod):
	stack = []
	acc = n
	while k != 1:
		phi = primes.euler_phi(mod,ignore=True)
		stack.append((phi,mod))
		mod = phi
		k-=1
	stack.reverse()
	#print stack
	for phi,mod in stack:
		acc = pow(n,acc%phi,phi)
	return acc%mod
Esempio n. 4
0
def smallest_k(n,min=0):
	if gcd(n,10) != 1:
		return None
	if gcd(n-9,n) != 1:
		return None
#		return handle_zero_divisors(n)
	factors = primes.all_factors(primes.factor(primes.euler_phi(n)))
	if factors[-1] < min:
		return None
	for factor in factors:
		factor = int(factor)
		if pow(10,factor,n) == 1:
			if factor < min:
				return None
			return factor
Esempio n. 5
0
def handle_zero_divisors(n):
	print "Zero divisors",
	factors = primes.all_factors(primes.factor(primes.euler_phi(n)))
	possibilities = PriorityQueue()
	for factor in factors:
		factor = int(factor)
		if pow(10,factor,n) == 1:
			possibilities.put((factor,factor,1))
	if possibilities.empty():
		return None
	while True: #should eventually terminate
		_,factor,multiple = possibilities.get()
		if pow(100,factor,n) == 1:
			print n,factor*multiple
			return factor*multiple
		possibilities.put((factor*(multiple*1),factor,multiple+1))
Esempio n. 6
0
def hyperexponent_mod_rec(n,k,mod):
	if k ==1:
		return n%mod
	phi = primes.euler_phi(mod,ignore=True)
	return pow(n,hyperexponent_mod_rec(n,k-1,mod),mod)%mod