here are two methods from a class that I wrote...these might be helpful. you'd still need to do a little work...
public boolean isPrime(long p){
long pAsALong = p;
long mySqrt = (long)Math.sqrt(pAsALong );
long divisor = 3;
if(p%2 == 2)
return true;
else if(p%2 == 0)
return false;
while(divisor <= mySqrt )
{
if(pAsALong % divisor == 0)
return false;
//only check odd numbers
divisor+=2;
}
return true;
}
//@return array list of longs that are prime factors
public ArrayList<Long> listPrimes(long upToWhat){
ArrayList<Long> listOfPrimes = new ArrayList<Long>(20);
listOfPrimes.add(2L);//add two
//only add odd numbers
for(long potentialPrime = 3;potentialPrime<= upToWhat; potentialPrime+=2){
if(isPrime(potentialPrime))
listOfPrimes.add(potentialPrime);
}
return listOfPrimes ;
}