0

hi all

i have a homework for Lehmann primality test and i have to know very big numbers as big as x**(2**128)

python is enough for 2**128 but when numbers bigger than it don't do it

my teacher python has a structure for it and i didn't find it for 2 days

thanks

4
Contributors
6
Replies
9
Views
5 Years
Discussion Span
Last Post by Thisisnotanid
0

decimal module has suppport of very long and accurate numbers, but I am not sure if it is enough for such extreme case. Usually you can find ways to work on powers with modulo, standard python pow supports second argument for modulo.

0
def mod_al(p,a):
	r=1
	c=(p-1)/2
	i=1
	while i<c+1:
		r=(r*a) %p
		i=i+1
	return r


p=input("give me number\n")
a=2
mod=mod_al(p,a)

if mod==1 or mod==p-1:
	print "this number can be prime"
else:
	print "this number don't prime"

this is my program maybe you can find a solution
it works but when numbers very big such as 2**50 it don't

Edited by weIIet: n/a

0

2**218 = 421249166674228746791672110734681729275580381602196445017243910144 and
2**50 = 1125899906842624
Either one is going to take a long time. As Tony said you should be using the decimal module.

this is my program maybe you can find a solution
it works but when numbers very big such as 2**50 it don't

Not unless there is a mind reader here who can intuit what "it don't" means. I don't think any one is going to waste hours running the code through bigger and bigger numbers until they find out what "it don't" means.

Edited by woooee: n/a

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.