Long decrement | Sololearn: Learn to code for FREE!

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

11/24/2020 12:24:07 PM

Александр

5 Answers

New Answer

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

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

+1

You're welcome..

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.

0

Thanks alot, Jayakrishna🇮🇳, will try ;3