Java while loop find largest prime factor

Description

Java while loop find largest prime factor


public class Main {
  public static void main(String[] args) {
    long maxNumber = 13 * 17 * 19 * 37 * 47 * 93 * 137l;
    long answer = maxNumber;
    for (long i = 2; i <= maxNumber / i; i++) {
      while (maxNumber % i == 0) {
        answer = i;/*from  w w w  .  ja  v  a 2 s.  com*/
        maxNumber /= i;
      }
    }
    if (maxNumber > 1) {
      answer = maxNumber;
    }
    System.out.println(answer);
  }
}



PreviousNext

Related