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

WA on test 13, Please help
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?
Re: WA on test 13, Please help
Posted by Teacher30 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).
Re: WA on test 13, Please help
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?
Re: WA on test 13, Please help
Posted by Teacher30 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?
Re: WA on test 13, Please help
Posted by Lev Panov 2 Mar 2009 21:42
Yep, you're right: I use GNU GCC.
Ok, I will try to use "long long" type.
Re: WA on test 13, Please help
Posted by yaho0o0 10 Apr 2009 01:58
you are so stupid max n is 21 not 100