+ 1

My code has been running for a long time with no output..

The problem here is the find the largest prime factor of 'x' in the code below .Different values of x works but the one in the code below has been running for a while now but no solution is appearing .So my question is how can i get the solution of this code and why is my code not giving me a result?? Code editor used: pycharm and sololearn https://code.sololearn.com/cv38khMj7Kvw/?ref=ap

30th Sep 2021, 4:52 PM
Ernesto
Ernesto - avatar
6 ответов
+ 2
First of all your code outputs nothing because "time out" happens. As sololearn doesnt let programs to run unlimited amount of time, your code simply has no time to execute. This is almost impossiable to fix for such time consuming programs, unless you ran it on your own computer rather than sololearn; However even if you would use your own computer to run this code it will take a long time. because of the fact that your code is extremely inefficient. To find out how to make your code more efficient visit this thread: https://www.sololearn.com/Discuss/2893038/?ref=app
30th Sep 2021, 5:03 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 1
Ernesto , there is no need to find all the primes in the range up to x https://code.sololearn.com/cFY3fCe1gWx6/?ref=app
1st Oct 2021, 1:49 AM
Vitaly Sokol
Vitaly Sokol - avatar
0
None of these codes work
30th Sep 2021, 5:20 PM
Ernesto
Ernesto - avatar
0
Ernesto, I never said they are complete solutions..... They are just a better way to check if number is a prime.
30th Sep 2021, 11:04 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
0
May check solution this way: print(max(__import__('sympy'). factorint(600851475143)))
30th Sep 2021, 11:25 PM
Vitaly Sokol
Vitaly Sokol - avatar
0
Vitaly Sokol , yeah true but it's sort of a hack, as the point is to write the program yourself rather than use a library...
30th Sep 2021, 11:43 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar