Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: The largest prime factor of the specific number.

1. ## The largest prime factor of the specific number.

Its my first post, so i would like to say Hello to Java Community. I'am absolutely new in programming and because of my young age(15) i have many problems to understand some aspects of it(especially advanced maths, logical thinking etc.). Nevertheless i think with an appropriate determination I can achieve success in this field of science. Lastly - I live in Poland thereby I could have sometimes problems with correct and "inteligent" english, but I am convinced that with your help my knowledge will rise up.

Coming to the point. Last time i tried to write a simple program which should find the largest prime factor of the number 600851475143.
```import java.util.Arrays;
import java.math.BigInteger;

public class PrimeFactor {

public static void main(String[] args) {
BigInteger[] Array = new BigInteger[i];
BigInteger number = new BigInteger("600851475143");
BigInteger number2 = new BigInteger("0");
BigInteger number3 = new BigInteger("0");
BigInteger PrimeFactor = new BigInteger ("0");
boolean select;
int i = 0;

while(PrimeFactor < number){
PrimeFactor++;

i++;
if(number%PrimeFactor == 0){
PrimeFactor = Array[i];

}
}

BigInteger largest = new BigInteger();
largest = Array[0];
for(int x=1; x<Array.length; x++) largest = max(Array[x],largest);

System.out.println(largest);

}

}```

I know that the program has many trivial errors( like there
`while(PrimeFactor < number){`
- "<" could not be used for integer) but i dont know what to use instead of it..

I will be grateful for your help.

2. ## Re: The largest prime factor of the specific number.

Welcome to the forum

Where exactly are you stuck?

3. ## Re: The largest prime factor of the specific number.

Hello.
I hope you understand the two core terms in your problem "prime" and "factor".
If yes then what is your strategy to find the largest prime factor of a given number? In your code you are not checking for if a factor is prime or not?
Use the tips below to write an efficient program:
- The largest prime factor of a given number 'n' is always <= 'n/2'.
- And you may be okay if you use long instead of bigint.

Syed.

4. ## Re: The largest prime factor of the specific number.

Don't by shy about your English. It's better than I've seen from most of the native speakers. Just be sure to describe specifically what you need help with and ask specific question. We've learned that it's a waste of time to guess and offer advice about something the poster understands perfectly.