Long decrement | Sololearn: Learn to code for FREE!


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; } }

11/24/2020 12:24:07 PM


5 Answers

New Answer


Ohh... long givenNumber = 255473976958L; Add L at end and try.. Try to reduce number of iterations.. And i>=given Number is enough I think...


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..


You're welcome..


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.


Thanks alot, Jayakrishna🇮🇳, will try ;3