The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor

08 July 2020

Views: 60

public class primeFactor
{
public static int largestPrimeFactor(long number) {
int i;
long copyOfInput = number;
for (i = 2; i <= copyOfInput; i++) {
if (copyOfInput % i == 0) {
copyOfInput /= i; i--; }

} return i;
}

public static void main(String[] args) {
System.out.println("Largest prime factor of number '%d' is %d %n"+ largestPrimeFactor(600851475143L));
}
}

Share