I'm trying to write in python3 to determine whether a number is a prime number or not.
I was specifically demanded to only use the following method:
"Divide the input with all the positive prime number smaller than it's square root."
For example, if the given number is 33, and then I would have to divide 33 with [2,3,5] (smaller than 5.xx, the square root of 33)
Meanwhile, in the process of finding [2,3,5], I can not use any method other than the demanded one.
So my code are as follow:
def is_prime(num):
import math
a=math.sqrt(num)
llist=[2,3]
pri=0
for i in range(2,int(a)+1):
root=math.sqrt(i)
for m in llist:
if m<root:
left=i%m
if left!=0:
llist.append(i)
if num in llist:
return True
for m in llist:
if num%m==0:
return False
if num%m!=0:
pri=pri+1
if pri==len(llist):
return True
and the code can not properly run when the input number exceed 7 figures, it just stop responding.
Apparently somewhere in my code there is an infinite loop that I can't figure out.
I'd be very grateful if someone can help me out with this one.