Jan-19-2018, 03:35 PM
Hello! I am new around here and trying to solve some basic challenges.
I wrote a code for getting prime factors for a number but got (IndexError: list index out of range).
while the code still runs for smaller numbers, it's very badly optimised so large numbers never get answers.
I need help in figuring out the error and the optimisations. Thanks in advance!
here's the code:
I wrote a code for getting prime factors for a number but got (IndexError: list index out of range).
while the code still runs for smaller numbers, it's very badly optimised so large numbers never get answers.
I need help in figuring out the error and the optimisations. Thanks in advance!
here's the code:
x=int(input()) y=1 flag=1 k=[] for y in range(1,x): for z in range(2,y): if(y==2)or(y%z!=0): flag=1 else: flag=0 break if(flag==1)and(y!=1): k.append(y) for p in range (0,x): if(x%k[p]==0): print(k[p])