java - Making solution for Project Euler more efficient -


Basically, I was having some problems working on this code, but after a little tweaking I was debugged and ready to go. .

I have gone through many modifications of this program. I only started with integer values, to know that the number was too large to fit in an int, then I turned into BigIntega, which proved to be a problem, but practical. From there, I switched for a long time (as it should be done from the beginning) and cut the runtime of my code to 8-times (or more).

Here is the code as it is now:

  tall qNum = 600851475143L; (Long = qNum - 1l; i * i> = qNum; i - = 2L) if (qNum% i == 0 & amp; amp; and; prime (i)) {System.out.println ( "Solution:" + I); // i for debugging returns; } Else System.out.println (i); // debugging 0L for return;  

and

  public stable boolean isPrime (long number) {// unnecessary statement for this problem (B / C for loop), but If useful for others (number% 2 == 0) returns incorrectly; For (long I = 3; i * i  

It's been running for hours and still has not got anything. I have noticed that to solve this puzzle, it is usually like parsing 560 GB of data. / <.

Any suggestions for speeding up?

Edit:

A lot of thanks,

Pre> public stable longest for most great process (ArrayList & lt; long & gt; factor, long number) {for (long I = 2; I & lt; = Math.sqrt (num); i ++ ) {If (num% i == 0) {factors.add (i); The greatest reaction return (factor, number / i); }} For (int i = factors.size () - 1; i>; i--) if returned (isPrime (factors.get (i)) num; return 0;} < / P>

and

  return the public stable boolean isPrime (long number) {if (num% 2 == 0); for (tall I = 3; i * i & Lt; = num; i + = 2) If (num% i == 0) false return; return true;}  

with RAN

  Greatest Process (New Arlist & lt; Long & gt; (), 600851475143);  

< P> My solution revolves around less than one hundredth of each other. Find the divisor, then divide the number by the separator and start over again. The maximum number of divisions you have is your goal.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -