ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1402. Cocktails

Lev Panov WA on test 13, Please help [5] // Problem 1402. Cocktails 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?
Teacher30 Re: WA on test 13, Please help [4] // Problem 1402. Cocktails 28 Feb 2009 05:55
Check your answers to maxtests:

21 => 138879579704209680000
20 => 6613313319248079980

PS: Idea of solution is correct, but you should store answer in suitable type ("long double" is not enough).
Lev Panov Re: WA on test 13, Please help [3] // Problem 1402. Cocktails 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?
Teacher30 Re: WA on test 13, Please help [2] // Problem 1402. Cocktails 2 Mar 2009 04:16
"long double" can store numbers about 10^{4000} but only first 19 digits are calculated right.

Btw, I think, you use some else compiler, not Intel-C++, am I right?
Lev Panov Re: WA on test 13, Please help [1] // Problem 1402. Cocktails 2 Mar 2009 21:42
Yep, you're right: I use GNU GCC.
Ok, I will try to use "long long" type.
yaho0o0 Re: WA on test 13, Please help // Problem 1402. Cocktails 10 Apr 2009 01:58
you are so stupid max n is 21 not 100