# Project Euler | Problem 3 | Largest prime factor

##
__Problem Description__ :

Project Euler Problem 3 |

##
__Concept__ :

**For example -**

- Prime factors of 12 are 2,2,3 and largest factor is 3.
- Prime factor of 315 are 3,3,5,7 and largest factor is 7.

So here we have to find the largest prime factor of 600851475143 and we are using below algorithm.

##
__Algorithm__ :

*source :**GeeksforGeeks*)

1) While limit is divisible by 2.

- Add 2 into TreeSet.
- Divide limit by 2.

2) At this point limit should be odd. Write for loop that starts from i=3 and run until square root of limit.

While limit is divisble by i.

3) If limit is prime number and greater than 2, then it won't become 1 by above two steps. So add limit to TreeSet if it is greater than 2.

- Add i into TreeSet.
- Divide limit by i.

3) If limit is prime number and greater than 2, then it won't become 1 by above two steps. So add limit to TreeSet if it is greater than 2.

4) TreeSet sort the elements in ascending order. So we will convert TreeSet to ArrayList and print last element of List because last element is largest prime factor.

##
__Java Program__ :

##
__Output__ :

Output - Project Euler Problem 3 |

##
__References__ :

*Thank you friends, I hope you have clearly understood the solution of this problem. If you have any doubt, suggestion or query please feel free to comment below. You can also discuss this solution in our forum.*

**Tags : Project Euler Problem 3 Solution, Mathematics problems, Largest prime factor, ArrayList, List, TreeSet, while loop, for loop, if statement.**

Project Euler | Problem 3 | Largest prime factor
Reviewed by Unknown
on
11/09/2016
Rating:

## No comments:

Please provide your valuable comments. If you have any suggestion please share with me I will work on it and if you have any question or doubt please ask, don't hesitate. I am your friend, i will clarify all your doubts.