What is the largest prime factor of the number...

Hello

I am taking part in the Euler Project, one of the problems is as follows:

"The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 317584931803?"

Now, I wrote a program that can do this. However, the problem arises with the number 317584931803. I realised that I cannot use long, int, byte or even float declarations with this number. I was told to use a class called "BigInteger".

Well, I modified my program according to this. And I wrote the following code...I know the code works, but there is one huge big problem.... IT TAKES FOREVER TO COMPUTE!

heck! forget 317584931803, instead I used 15 and its still computing! Its been 5 mins already! Maybe its got caught in some infinite loop, but I doubt that...

[code]

import java.math.*;

public class euler6 {

static BigInteger a[]=new BigInteger[999];

static int j=0;

static BigInteger bi = new BigInteger("15"); //This is the number whos largest prime factor you have to find.

static BigInteger i=new BigInteger("2");

static final BigInteger one=new BigInteger("1");

public static void main (String arhs[]){

for(;i.compareTo(bi)==-1;i.add(one))

if ((bi.mod(i).equals("0"))&& (findPrime(i)))

{a[j]=i;

j++;}

for(int f=0;f<a.length;f++)

System.out.print(a[f]+" ");

}

public static boolean findPrime(BigInteger n){

BigInteger x=new BigInteger("2");

for(;x.compareTo(n)==-1;x.add(one))

if (n.mod(x).equals("0"))

return false;

return true;

}

}>

[1646 byte] By [GizmoCa] at [2007-9-29 20:25:23]
# 1
nm, I figured it out. :)
GizmoCa at 2007-7-16 0:37:24 > top of Java-index,Other Topics,Algorithms...
# 2
Actually, someone much smarter than GizmoC figured it out for him: http://forum.java.sun.com/thread.jsp?thread=478348&forum=54&message=2223652MOD
duffymoa at 2007-7-16 0:37:24 > top of Java-index,Other Topics,Algorithms...