Skip to content

Instantly share code, notes, and snippets.

@davidawad
Created August 16, 2014 04:14
Show Gist options
  • Save davidawad/1fa51d09c36bc7c831e2 to your computer and use it in GitHub Desktop.
Save davidawad/1fa51d09c36bc7c831e2 to your computer and use it in GitHub Desktop.
My solution to the Project Euler+ Challenge #3 on Hackerrank
import math
def factor(n):
myList = []
for i in range(1, int(n ** 0.5 + 1)):
if n % i == 0:
if (i != n/i):
myList.append(i)
myList.append(n / i)
else:
myList.append(i)
return myList
def prime(n):
if n == 2 or n == 3:
return True
elif n < 2 or n % 2 == 0:
return False
elif n < 9:
return True
elif n % 3 == 0:
return False
r = int(math.sqrt(n))
f = 5
while f <= r:
if n % f == 0 or n % (f + 2) == 0:
return False
else:
f += 6
return True
buff = int(input())
for _ in range (0,buff):
curr = int(input())
clist = factor(curr)
i,lprime=0,0
blist=[float(u) for u in clist]
##print(str(clist))
while i<=len(clist)-1:
##print ('i is '+str(i) +' at this time')
##print ('clist[i] is '+str(clist[i]) +' at this time')
if prime(clist[i]):
if clist[i]>lprime:
lprime=clist[i]
i+=1
print(str(int(lprime)))
@davidawad
Copy link
Author

got a perfect score!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment