Largest Prime Factor

HardMathNumber Theory

Description

Given an integer n ≥ 2, return the largest prime factor of n.

Examples

Input:n = 13195
Output:29
Explanation:

The factorization 13195 = 5 * 7 * 13 * 29 has largest prime factor 29.

Input:n = 2
Output:2
Explanation:

Since 2 is itself prime, its largest prime factor is 2.

Input:n = 600851475143
Output:6857
Explanation:

The Project Euler problem 3 value 600851475143 has largest prime factor 6857.

Constraints

  • 2 ≤ n ≤ 10¹²

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!