+ 1

Long decrement

I need to find the largest prime factor of a long number. To do so, I'm using a loop with decrement , however it doesn't seem to work. On the other hand, if I replace this number with any other int - it will work. What am I missing? long givenNumber = 255473976958; long largestPrimeFactor; for (long i = givenNumber; i >0; --i) { if (givenNumber % i == 0 && i != givenNumber) { largestPrimeFactor = i; System.out.println(largestPrimeFactor); break; } }

24th Nov 2020, 12:24 PM
Александр
5 odpowiedzi
+ 4
Ohh... long givenNumber = 255473976958L; Add L at end and try.. Try to reduce number of iterations.. And i>=given Number is enough I think...
24th Nov 2020, 12:51 PM
Jayakrishna 🇮🇳
+ 2
You cannot get here that because it definately gets time out.. It mostly take a minute but SoloLearn can lost connection inbetween so try it in system, not here..
24th Nov 2020, 12:43 PM
Jayakrishna 🇮🇳
+ 1
You're welcome..
24th Nov 2020, 12:57 PM
Jayakrishna 🇮🇳
0
Well, that's the other problem. I'm running it in Intellij Idea IDE, yet it still doesn't seem to work. I have a feeling like I will have to find other way.
24th Nov 2020, 12:48 PM
Александр
0
Thanks alot, Jayakrishna🇮🇳, will try ;3
24th Nov 2020, 12:56 PM
Александр