R
Rahul
HI.
Python , with its support of arbit precision integers, can be great
for number theory. So i tried writing a program for testing whether a
number is prime or not. But then found my function painfully slow.Here
is the function :
from math import sqrt
def isPrime(x):
if x%2==0 or x%3==0:
return 0
i=5
sqrt=sqrt(x)
sqrt=sqrt(x)+1
while i<sqrt:
if x%i==0:
return 0
i=i+2
if x%i==0:
return 0
i=i+4
return 1
Try testing some number like 2**61-1.Its very slow.In comparision
Mathematica not only tests but finds factors in an instant by
Divisors[x].
Does anybody have a faster way to test for primality.(and not just
pseudoprime).
rahul
Python , with its support of arbit precision integers, can be great
for number theory. So i tried writing a program for testing whether a
number is prime or not. But then found my function painfully slow.Here
is the function :
from math import sqrt
def isPrime(x):
if x%2==0 or x%3==0:
return 0
i=5
sqrt=sqrt(x)
sqrt=sqrt(x)+1
while i<sqrt:
if x%i==0:
return 0
i=i+2
if x%i==0:
return 0
i=i+4
return 1
Try testing some number like 2**61-1.Its very slow.In comparision
Mathematica not only tests but finds factors in an instant by
Divisors[x].
Does anybody have a faster way to test for primality.(and not just
pseudoprime).
rahul