Create isprime.py

This commit is contained in:
Torma Kristóf 2019-04-26 15:36:50 +02:00 committed by GitHub
parent 496fafa172
commit e7fa428112
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

14
functions/isprime.py Normal file
View File

@ -0,0 +1,14 @@
def isprime(event,context):
n= event['data']
if n == 2 or n == 3: return "Prime"
if n < 2 or n%2 == 0: return "Not Prime"
if n < 9: return "Prime"
if n%3 == 0: return "Not Prime"
r = int(n**0.5)
f = 5
while f <= r:
print '\t',f
if n%f == 0: return "Not Prime"
if n%(f+2) == 0: return "Not Prime"
f +=6
return "Prime"