#include <stdio.h>
long long unsigned silnia_iter(unsigned);
long long unsigned silnia_rekur(unsigned);
int main(int argc, char* argv[])
{
printf("%I64u\n", silnia_iter
(0)); printf("%I64u\n", silnia_iter
(1)); printf("%I64u\n", silnia_iter
(2)); printf("%I64u\n", silnia_iter
(5));
printf("%I64u\n", silnia_rekur
(0)); printf("%I64u\n", silnia_rekur
(1)); printf("%I64u\n", silnia_rekur
(2)); printf("%I64u\n", silnia_rekur
(5));
return 0;
}
long long unsigned silnia_iter(unsigned n)
{
if (n < 0)
{
return -1;
}
else
{
long long unsigned silnia = 1;
size_t i;
for (i = 1; i <= n; i++)
{
silnia *= i;
}
return silnia;
}
}
long long unsigned silnia_rekur(unsigned n)
{
if (n < 0)
{
return -1;
}
else if (n < 2)
{
return 1;
}
else
{
return n*silnia_rekur(n-1);
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+Cgpsb25nIGxvbmcgdW5zaWduZWQgc2lsbmlhX2l0ZXIodW5zaWduZWQpOwpsb25nIGxvbmcgdW5zaWduZWQgc2lsbmlhX3Jla3VyKHVuc2lnbmVkKTsKCmludCBtYWluKGludCBhcmdjLCBjaGFyKiBhcmd2W10pIAp7CglwcmludGYoIiVJNjR1XG4iLCBzaWxuaWFfaXRlcigwKSk7CiAgICBwcmludGYoIiVJNjR1XG4iLCBzaWxuaWFfaXRlcigxKSk7CiAgICBwcmludGYoIiVJNjR1XG4iLCBzaWxuaWFfaXRlcigyKSk7CiAgICBwcmludGYoIiVJNjR1XG4iLCBzaWxuaWFfaXRlcig1KSk7CiAgICAKICAgIHByaW50ZigiJUk2NHVcbiIsIHNpbG5pYV9yZWt1cigwKSk7CiAgICBwcmludGYoIiVJNjR1XG4iLCBzaWxuaWFfcmVrdXIoMSkpOwogICAgcHJpbnRmKCIlSTY0dVxuIiwgc2lsbmlhX3Jla3VyKDIpKTsKICAgIHByaW50ZigiJUk2NHVcbiIsIHNpbG5pYV9yZWt1cig1KSk7CiAgICAKICAgIHJldHVybiAwOwp9Cgpsb25nIGxvbmcgdW5zaWduZWQgc2lsbmlhX2l0ZXIodW5zaWduZWQgbikKewogICAgaWYgKG4gPCAwKQogICAgewogICAgICAgIHJldHVybiAtMTsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICBsb25nIGxvbmcgdW5zaWduZWQgc2lsbmlhID0gMTsKICAgICAgICBzaXplX3QgaTsKICAgICAgICAKICAgICAgICBmb3IgKGkgPSAxOyBpIDw9IG47IGkrKykKICAgICAgICB7CiAgICAgICAgICAgIHNpbG5pYSAqPSBpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICByZXR1cm4gc2lsbmlhOwogICAgfQp9Cgpsb25nIGxvbmcgdW5zaWduZWQgc2lsbmlhX3Jla3VyKHVuc2lnbmVkIG4pCnsKICAgIGlmIChuIDwgMCkKICAgIHsKICAgICAgICByZXR1cm4gLTE7CiAgICB9CiAgICBlbHNlIGlmIChuIDwgMikKICAgIHsKICAgICAgICByZXR1cm4gMTsKICAgIH0KICAgIGVsc2UKICAgIHsKICAgICAgICByZXR1cm4gbipzaWxuaWFfcmVrdXIobi0xKTsKICAgIH0KfQ==