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


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: The largest prime factor of the specific number.

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: The largest prime factor of the specific number.

    Welcome to the forum

    Where exactly are you stuck?

  3. #3
    Member
    Join Date
    Jul 2013
    Posts
    219
    Thanks
    0
    Thanked 18 Times in 17 Posts

    Default 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. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default 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.

Similar Threads

  1. Check if number is prime number or not problem[SOLVED]
    By kinkita in forum Loops & Control Statements
    Replies: 9
    Last Post: July 17th, 2013, 10:59 AM
  2. 3x3 array find largest number
    By joecan2010 in forum Loops & Control Statements
    Replies: 1
    Last Post: November 27th, 2012, 11:56 PM
  3. Combine Prime Factor Code into JPanel
    By BobDole6395 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2012, 06:24 AM
  4. Prime number solver.
    By Danny123 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: June 4th, 2012, 05:30 AM
  5. Find the two largest number
    By vendettabf in forum What's Wrong With My Code?
    Replies: 15
    Last Post: December 29th, 2011, 01:23 PM