|
|
back to boardWA on test 13, Please help 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 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 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 "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 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 |
|
|