fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Ideone
  8. {
  9. public static interface Factorial{
  10. public int calculate(int n);
  11. }
  12.  
  13. public static enum FactorialFactory{
  14. INSTANCE;
  15.  
  16. public static FactorialFactory getFactoryInstance(){
  17. return INSTANCE;
  18. }
  19.  
  20. public Factorial createNewInstance(){
  21. return new Factorial(){
  22. @Override
  23. public int calculate(int n){
  24. if(n < 0){
  25. }
  26. int res = 1;
  27. while(n>0){
  28. res = res*(n--);
  29. }
  30. return res;
  31. }
  32. };
  33. }
  34. }
  35.  
  36. public static void main (String[] args)
  37. {
  38. Factorial fac = FactorialFactory.getFactoryInstance().createNewInstance();
  39. for(int k=1;;k++){
  40. int factorial = fac.calculate(k);
  41. System.out.printf("%02d! = %s%n", k,
  42. String.format("%32s", Integer.toBinaryString(factorial)).replace(' ', '0')
  43. );
  44. if(factorial == 0){
  45. break;
  46. }
  47. }
  48. }
  49. }
Success #stdin #stdout 0.09s 380160KB
stdin
Standard input is empty
stdout
01! = 00000000000000000000000000000001
02! = 00000000000000000000000000000010
03! = 00000000000000000000000000000110
04! = 00000000000000000000000000011000
05! = 00000000000000000000000001111000
06! = 00000000000000000000001011010000
07! = 00000000000000000001001110110000
08! = 00000000000000001001110110000000
09! = 00000000000001011000100110000000
10! = 00000000001101110101111100000000
11! = 00000010011000010001010100000000
12! = 00011100100011001111110000000000
13! = 01110011001010001100110000000000
14! = 01001100001110110010100000000000
15! = 01110111011101110101100000000000
16! = 01110111011101011000000000000000
17! = 11101110110011011000000000000000
18! = 11001010011100110000000000000000
19! = 00000110100010010000000000000000
20! = 10000010101101000000000000000000
21! = 10111000110001000000000000000000
22! = 11100000110110000000000000000000
23! = 00110011011010000000000000000000
24! = 11010001110000000000000000000000
25! = 01111011110000000000000000000000
26! = 10010001100000000000000000000000
27! = 01011000100000000000000000000000
28! = 10101110000000000000000000000000
29! = 10110110000000000000000000000000
30! = 01010100000000000000000000000000
31! = 00101100000000000000000000000000
32! = 10000000000000000000000000000000
33! = 10000000000000000000000000000000
34! = 00000000000000000000000000000000