I have a bit of code which will take an integer as an input and print out a sorted list of that integers prime factors.
It works perfectly for pretty much all numbers, for example when the input is 100 it will print [2, 2, 5, 5] and for 1235632 it will spit out [2, 2, 3, 3, 343237].
However for far larger numbers it will not print the factors out in order, I am not sure if this is an unresolved issue in the code I have overlooked or if it is something else.
For instance when I put in 1234567891011121314151617 it will output [3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 43, 109, 104281, 1394027], which is obviously not sorted and I cannot for the life of me figure out why.
I am using what I think is the most recent version of pycharm.
Anyway, this is the code:
from math import floor
from math import sqrt
n = int(input("Enter a number to be split into its prime factors"))
FList = []
k = 1
while n != 1:
k = k + 1
s = floor(sqrt(n))
if k > s:
FList.append(int(n))
break
if n % k == 0:
n = n/k
FList.append(k)
k = 1
print(FList)
Edit: Just to clarify I would rather fix the program as it is then use a sorting algorithm to help clean up.
As pointed out by someone else, the factors of the large number are complete garbage so I guess the current question is now why it prints those numbers.
nis doing quite a bit of work here and the reuse of variable might be causing problems. Try giving variables more descriptive names and using each variable strictly for one purpose.