fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. template<unsigned long long num, unsigned long long npass>
  5. struct Factorial_r {
  6. enum { value = num };
  7. int pass;
  8. Factorial_r() {
  9. Factorial_r<num*(npass-1),npass-1> a;
  10. std::wcout << num << " " << npass << std::endl;
  11. pass = a.pass;
  12. }
  13. };
  14.  
  15. // Entrance structure
  16. template<unsigned long long n>
  17. struct Factorial{
  18. int value;
  19. Factorial() {
  20. Factorial_r<n*(n-1),n-1> a;
  21. std::wcout << n << std::endl;
  22. value = a.pass;
  23. }
  24. };
  25.  
  26. template<unsigned long long num>
  27. struct Factorial_r<num,2>
  28. {
  29. enum { value = num };
  30. int pass;
  31. Factorial_r() {
  32. std::wcout << value << " 2" << std::endl;
  33. pass = num;
  34. }
  35. };
  36.  
  37. int main()
  38. {
  39. Factorial<10> a;
  40. std::wcout << a.value;
  41.  
  42. char foo[50];
  43. gets(foo);
  44. return 0;
  45. }
Success #stdin #stdout 0.02s 2876KB
stdin
Standard input is empty
stdout
3628800 2
1814400 3
604800 4
151200 5
30240 6
5040 7
720 8
90 9
10
3628800