I'm having issues with Euler Problem 3 (http://projecteuler.net/index.php?section=problems&id=3).
My issue with my code is that the compiler says "running user program" and then never stops, so I guess it must be an infinite loop.
I know that a lot my code/technique to solving this problem is probably wrong and that I could just look up the right code/approach on the internet. However, I'm just trying to find a way to solve the problem on my own and then after that looking at the better code.
So here's what I've come up with so far... I think the issue is an infinite loop, but I don't see where/how that's occurring...
public class Euler3{
public static void main(String[] args){
long x = 200;
long y = x-1;
PrimeFactor myPrime = new PrimeFactor();
while(y > 1){
myPrime.divide(x, y);
if(myPrime.divide(x, y) >= 1){
System.out.println(myPrime.getDivisor() + "^" + myPrime.getCount());
}//if
y--;
}//while
}//main
}//class
public class PrimeFactor{
public long divisor = 2;
public long dividend = 0;
public long quotient = 0;
public long count = 0;
public long divide(long x, long y) {
dividend = x;
divisor = y;
while(dividend%divisor==0){
quotient = dividend / divisor;
divisor = quotient;
count++;
}//while
return count;
}//divide
public long getDivisor(){
return divisor;
}//getDivisor
public long getCount(){
return count;
}//getCount
}
Also, everything is a long right now, because eventually I want to solve it for the really big number. I'm just seeing if what I did works with small numbers right now...
I really appreciate any help!
This post has been edited by JackOfAllTrades: 07 August 2010 - 10:53 AM
Reason for edit:: Switched quote tags to code tags

New Topic/Question
Reply



MultiQuote





|