fork download
  1. class ReverseFactorial {
  2. public static void main(String[] args) {
  3. int[] input = {
  4. 3628800,
  5. 479001600,
  6. 6,
  7. 18
  8. };
  9.  
  10. for(int cur: input)
  11. System.out.printf("%d: %s\n", cur, reverseFactorial(cur));
  12. }
  13.  
  14. public static String reverseFactorial(int x) {
  15. for(int i = 0; factorial(i) <= x; i++)
  16. if(factorial(i) == x)
  17. return Integer.toString(i) + "!";
  18. return "NONE";
  19. }
  20.  
  21. public static int factorial(int x) {
  22. return x > 0 ? x * factorial(x - 1) : 1;
  23. }
  24. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
3628800: 10!
479001600: 12!
6: 3!
18: NONE