+ 1
Help with #3 Project Euler
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Code times out before it can get the answer. Any tips to optimise it? https://code.sololearn.com/cX5lh84cTpUV/?ref=app Edit 1: Sorry I accidentally deleted part of my code. I fixed it now Edit 2: Thanks for your help everyone. I solved it :)
2 Antworten
+ 4
I think your code is not good. It gives also time out for 12.
Maybe you should find a better way. In my code I calculated all prime factores.
First search for the first divisor. This is always prime.
number / divisor -> prime? If yes you are done if not the result gets your new number and you repeat this process.
For example:
12
First divisor is 2.
12 / 2 = 6
6
First divisor is 2.
6 / 2 = 3
Prime factors: 2, 2, 3
+ 2
JOHN PETERSON
It should be: largest = k
instead of: k = largest
There are better (optimized) ways to achieve the goal as Denise Roßberg and fork() have suggested.