fork download
  1. import java.math.BigInteger;
  2.  
  3. public class Factorial {
  4. public static int[] primes = {2,3,5,7,11,13,17,19,23,29,31,37};
  5. public static BigInteger computeFactorial(int n) {
  6. if (n==0) {
  7. return new BigInteger(String.valueOf(1));
  8. } else {
  9. return new BigInteger(String.valueOf(n)).multiply(computeFactorial(n-1));
  10. }
  11. }
  12. public static String getPowers(int n){
  13. BigInteger input = computeFactorial(n);
  14. StringBuilder sb = new StringBuilder();
  15. int count = 0;
  16. for (int i = 0; i < primes.length && input.intValue() != 1;) {
  17. BigInteger[] result = input.divideAndRemainder(new BigInteger(String.valueOf(primes[i])));
  18. if (result[1].intValue() == 0) {
  19. input = input.divide(new BigInteger(String.valueOf(primes[i])));
  20. count++;
  21. if (input.intValue() == 1) {sb.append(primes[i] + "(" + count + ") ");}
  22. } else {
  23. if (count!=0)
  24. sb.append(primes[i] + "(" + count + ") ");
  25. count = 0;
  26. i++;
  27. }
  28. }
  29. return sb.toString();
  30. }
  31. public static void main(String[] args) {
  32. System.out.println(getPowers(37));
  33. }
  34. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:3: error: class Factorial is public, should be declared in a file named Factorial.java
public class Factorial {
       ^
1 error
stdout
Standard output is empty