#include <iostream>
template <int N>
struct Factorial
{
enum
{
value = N * Factorial<N - 1>::value
};
};
template <>
struct Factorial<0>
{
enum
{
value = 1
};
};
unsigned int factorial(unsigned int n)
{
return (n == 0)? 1 : n * factorial(n - 1);
}
using namespace std;
int main()
{
const int x = factorial(0);
const int y = factorial(10);
const int z = Factorial<0>::value;
const int v = Factorial<10>::value;
cout << x << endl
<< y << endl
<< z << endl
<< v << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGUgPGludCBOPgpzdHJ1Y3QgRmFjdG9yaWFsCnsKICAgIGVudW0KCXsKCQl2YWx1ZSA9IE4gKiBGYWN0b3JpYWw8TiAtIDE+Ojp2YWx1ZQoJfTsKfTsKIAp0ZW1wbGF0ZSA8PgpzdHJ1Y3QgRmFjdG9yaWFsPDA+CnsKICAgIGVudW0KCXsKCQl2YWx1ZSA9IDEKCX07Cn07Cgp1bnNpZ25lZCBpbnQgZmFjdG9yaWFsKHVuc2lnbmVkIGludCBuKQp7CiAgICByZXR1cm4gKG4gPT0gMCk/IDEgOiBuICogZmFjdG9yaWFsKG4gLSAxKTsgCn0KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICBjb25zdCBpbnQgeCA9IGZhY3RvcmlhbCgwKTsKICBjb25zdCBpbnQgeSA9IGZhY3RvcmlhbCgxMCk7CiAgY29uc3QgaW50IHogPSBGYWN0b3JpYWw8MD46OnZhbHVlOwogIGNvbnN0IGludCB2ID0gRmFjdG9yaWFsPDEwPjo6dmFsdWU7CgogIGNvdXQgPDwgeCA8PCBlbmRsCiAgICAgICA8PCB5IDw8IGVuZGwKICAgICAgIDw8IHogPDwgZW5kbAogICAgICAgPDwgdiA8PCBlbmRsOwoKICByZXR1cm4gMDsKfQ==