fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.math.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. List<BigInteger> factors = new LinkedList<BigInteger>();
  10. //BigInteger number = new BigInteger("600851475143");
  11. BigInteger number = new BigInteger("13195");
  12. BigInteger i = new BigInteger("2");
  13. while(number.compareTo(BigInteger.ONE) > 0) {
  14. if(number.mod(i).equals(BigInteger.ZERO)) {
  15. factors.add(i);
  16. number = number.divide(i);
  17. } else {
  18. i = i.add(BigInteger.ONE);
  19. }
  20. }
  21.  
  22. for(int j = 0; j < factors.size(); j++) {
  23. System.out.println(factors.get(j));
  24. }
  25. }
  26. }
Success #stdin #stdout 0.08s 212416KB
stdin
Standard input is empty
stdout
5
7
13
29