Posted:

**Tue Aug 09, 2005 11:18 am**Some simple cases:
Output:

Input generator:
Output from my first program (uses long double, and binomial identities), to 10 decimal places:
And here's output from another accepted program, which uses double, and approximation by logarithms:
If you get similar answers and still WA, post you code here.

Code: Select all

```
5
1
0
1
-1
1
1
1
-555.5559
1
555.5559
```

Code: Select all

```
Case #1: 0.000
Case #2: -1.000
Case #3: 1.000
Case #4: -555.556
Case #5: 555.556
```

Input generator:

Code: Select all

```
#include <stdio.h>
#include <stdlib.h>
unsigned r = 123456; int T = 20, a[65536], i, n;
int R(unsigned m) { r = r * 1812433253 + 1; return (r >> 4) % m; }
int C(const void *p, const void *q) { return (*(int *)q - *(int *)p); }
int main() {
for(printf("%d\n",T);T--;) {
for(printf("%d\n",n=1+R(50000)),i=n;i--;)a[i]=R(2000000)-1000000;
qsort(a,n,sizeof(a[0]),&C);
while(n--)printf("%s%d.%.3d%c",(a[n]<0)?"-":"",abs(a[n]/1000),abs(a[n])%1000,n?' ':'\n');
}
return 0;
}
```

Code: Select all

```
Case #1: -5.1383833008
Case #2: -7.5212485514
Case #3: -5.4755549144
Case #4: -22.0564143198
Case #5: -14.7081045826
Case #6: 2.1670052646
Case #7: -2.8371366794
Case #8: -64.6690314518
Case #9: -2.8069371800
Case #10: -6.3711452901
Case #11: -0.1070479581
Case #12: 9.9847964413
Case #13: -4.9372260331
Case #14: -5.3130527357
Case #15: 5.2135842771
Case #16: 3.0378944456
Case #17: 5.2404084182
Case #18: -8.1282949430
Case #19: 1.4519873897
Case #20: 0.7415996176
```

Code: Select all

```
Case #1: -5.1383659629
Case #2: -7.5212348259
Case #3: -5.4755465033
Case #4: -22.0564002421
Case #5: -14.7080626664
Case #6: 2.1670022202
Case #7: -2.8371272209
Case #8: -64.6689788484
Case #9: -2.8069336197
Case #10: -6.3711423685
Case #11: -0.1070486464
Case #12: 9.9847738878
Case #13: -4.9372089784
Case #14: -5.3130318235
Case #15: 5.2135703089
Case #16: 3.0378827475
Case #17: 5.2403945592
Case #18: -8.1282549736
Case #19: 1.4519816612
Case #20: 0.7415916422
```