ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1402. Cocktails

Posted by Lev Panov 27 Feb 2009 21:26
This is my solution:

#include <stdio.h>

long double fact( long double n )
{
if (n < 2)
return 1;
else
return n * fact(n - 1);
}

int main( void )
{
long double n, nfac, ans = 0, i;

scanf("%Lf", &n);

if (n < 2)
{
printf("0");
return 0;
}

nfac = fact(n);

for (i = 2; i < n; i ++)
ans += nfac / fact(n - i);

ans += nfac;

printf("%.0Lf", ans);

return 0;
}

WTF?
Posted by Teacher30 28 Feb 2009 05:55

21 => 138879579704209680000
20 => 6613313319248079980

PS: Idea of solution is correct, but you should store answer in suitable type ("long double" is not enough).
Posted by Lev Panov 1 Mar 2009 21:06
Hmm, I actually have correct answers for n = 20 and 21.
And "long double" is extremely big type, for example:
100 =>
253686955560127297296368144135170000933446331847165085913916476338770833469945019420289324705338829425834316771115322447713278811189027647015804045741541818368
=))
What's wrong then?