Largest prime factor

 
Problem3:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?

Solution:


package euler;
/*
 * The prime factors of 13195 are 5, 7, 13 and 29.
   What is the largest prime factor of the number 600851475143 ?
 */
public class Probem3 {

	public static void main(String args[])
	{
		long start_time= System.currentTimeMillis();
		long factor=600851475143L;
		long max_factor=1;
		int counter=0;
		while(counter1)
		{
			if(factor%index==0)
			{
				if(index>max_factor)
					max_factor=index;
					
				factor=factor/index;
			}
			else
			{
			index++;	
			}
		}
		counter++;
		}
		System.out.println("Largest prime factor of the number 600851475143 is :"+max_factor);
		System.out.println("Total time taken:"+ ((System.currentTimeMillis()-start_time)/1000)+"sec");  	
	}
	
}


Result :
Largest prime factor of the number 600851475143 is :6857
Total time taken:0sec

Tagged with: , , , ,
Posted in Euler

Leave a comment