#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>
const long PRECISION = 5000;
const int CALC_PREC = 7;
const int CALC_ALPHA = 10;
static long base;
static long last;
void add(long z[], long x[], long y[])
{
long i, t, r = 0;
for (i = last; i >= 0; --i) {
t = x[i] + y[i] + r;
r = t / base;
z[i] = t - r * base;
}
}
void sub(long z[], long x[], long y[])
{
long i, t, r = 1;
for (i = last; i >= 0; --i) {
t = x[i] + (base - y[i] - 1) + r;
r = t / base;
z[i] = t - r * base;
}
}
void mul(long z[], long x[], long k)
{
long i, t, r = 0;
for (i = last; i >= 0; --i) {
t = x[i] * k + r;
r = t / base;
z[i] = t - r * base;
}
}
void dvd(long z[], long x[], long k)
{
long i, r = 0;
double t;
for (i = 0; i <= last; ++i) {
t = x[i] + (double)r * base;
z[i] = t / k;
r = t - (double)k * z[i];
}
}
void print(long x[]) {
int i, j, c1, c2;
int d;
long t;
c1 = c2 = 0;
for (i
= 0; i
< ceil((double)PRECISION
/ CALC_PREC
) + 1; i
++) { t = x[i];
for (j = CALC_PREC - 1; j >= 0; --j) {
d
= t
/ (long)pow(10, j
); t
= t
- d
* (long)pow(10, j
); if (++c1 >= 10) {
c1 = 0;
if (++c2 >= 5) {
c2 = 0;
}
}
}
}
}
int iszero(long x[]) {
int i;
int flag = 1;
for (i = 0; i <= last; i++)
if (x[i] != 0) {
flag = 0;
break;
}
return flag;
}
int main()
{
long n;
long *s, *t;
base
= pow(10, CALC_PREC
); last
= ceil((double)PRECISION
/ CALC_PREC
) + CALC_ALPHA
;
s
= malloc((last
+ 1) * sizeof(long)); t
= malloc((last
+ 1) * sizeof(long)); memset(s
, 0, (last
+ 1) * sizeof(long)); memset(t
, 0, (last
+ 1) * sizeof(long)); t[0] = base / 2;
n = 2;
while (!iszero(t)) {
add(s, s, t);
n++;
dvd(t, t, n);
}
print(s);
return 0;
}
/* end */
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4K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NpemVvZihsb25nKSk7CiAgdCA9IG1hbGxvYygobGFzdCArIDEpICogc2l6ZW9mKGxvbmcpKTsKICBtZW1zZXQocywgMCwgKGxhc3QgKyAxKSAqIHNpemVvZihsb25nKSk7CiAgbWVtc2V0KHQsIDAsIChsYXN0ICsgMSkgKiBzaXplb2YobG9uZykpOwogIHRbMF0gPSBiYXNlIC8gMjsKICBuID0gMjsKICB3aGlsZSAoIWlzemVybyh0KSkgewogICAgYWRkKHMsIHMsIHQpOwogICAgbisrOwogICAgZHZkKHQsIHQsIG4pOwogIH0KICBwcmludGYoImUgPSAyLlxuIik7CiAgcHJpbnQocyk7CgogIGZyZWUocyk7CiAgZnJlZSh0KTsKICByZXR1cm4gMDsKfQovKiBlbmQgKi8=