Problem:
Problem F:
Ben Toh
As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while others have to have cup ramen or something with tear in their eyes.
A senior high school student, Sato, is one of wolves. A dormitry he lives doesn't serve a dinner, and his parents don't send so much money. Therefore he absolutely acquire the half-priced box lunch and save his money. Otherwise he have to give up comic books and video games, or begin part-time job.
Since Sato is an excellent wolf, he can acquire the discounted box lunch in 100% probability on the first day. But on the next day, many other wolves cooperate to block him and the probability to get a box lunch will be 50%. Even though he can get, the probability to get will be 25% on the next day of the day. Likewise, if he gets a box lunch on a certain day, the probability to get on the next day will be half. Once he failed to get a box lunch, probability to get would be back to 100%.
He continue to go to supermaket and try to get the discounted box lunch for
n
days. Please write a program to computes the expected value of the number of the discounted box lunches he can acquire.
Input
Input consists of several datasets.
Input for a single dataset is given as a single integer
n
.
Input terminates with a dataset where
n
= 0.
Output
For each dataset, write a line that contains an expected value. You may print any number of digits after the decimal point. Answers that have an error less than 1.0e-2 will be accepted.
Constraints
1 ≤
n
≤ 100,000
Sample Input
1
2
3
0
Output for the Sample Input
1.00000000
1.50000000
2.12500000

Submitted solutions:

code_snippet: #include<stdio.h>
#define stepn 70
double f[100001],g[100001];

int max(int o,int p) {return o>p?o:p;}
int min(int o,int p) {return o<p?o:p;}

double pow1(int o)
{
    if (o==0) return 1.0;
    if (o==1) return 0.5;
    double ans=pow1(o/2);
    ans*=ans;
    if (o&1) ans*=0.5;
    return ans;
}

int main()
{
    f[1]=1.0,g[1]=1.0;
    double u=1,v=1;
    for (int i=2;i<=100000;i++)
    {
        u*=0.5;
        v*=u;
        g[i]=i;
        f[i]+=g[i]*v;
        for (int j=2;j<=i;j++)
        if (j>stepn) {break;} else
        {
            f[i]+=(pow1((j-1)*(j-2)/2)*(1-pow1(j-1))*(f[i-j]+g[j-1]));
        }
        //f[i]=1.0+0.5*(f[i-2]+g[i-1]);
        //g[i]=0.5*(g[i-1]+f[i]);
    }

    int n;
    while (true)
    {
        scanf("%d",&n);
        if (n==0) break;
        printf("%.3f\n",f[n]);
    }
    return 0;
}
accuracy: 1
time_ms: 180
memory_kb: 4428
final_rank: 6

code_snippet: #include<bits/stdc++.h> 
using namespace std;
using ll=long long;

void solve(ll N){
	vector<double> DP(N+1,0.0);
	DP[1]=1.0;
	cout<<fixed<<setprecision(15);
	for(int n=2;n<=N;n++){
		double p=0.5;
		double q=1.0;
		for(int j=1;j<min(70,n);j++){
			DP[n]+=q*(1.0-p)*(j+DP[n-j-1]);
			q*=p;
			p*=0.5;
		}
		DP[n]+=q*n;
	}
	cout<<DP[N]<<endl;
}

int main(){
	
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	
	ll N;
	while(cin>>N,N!=0)solve(N);
	
}
accuracy: 1
time_ms: 70
memory_kb: 4532
final_rank: 4

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  cout << fixed << setprecision(20);
  while(1){
    int n;cin >> n;
    if(n == 0)break;
    vector<long double> dp(50);
    vector<long double> p(50);
    p[0] = 1;
    rep(i,n){
      vector<long double> DP(50);
      vector<long double> P(50);
      rep(j,50){
        if(dp[j] < 0)continue;
        if(j+1 < 50){
          DP[j+1] = (dp[j]+p[j])/(1ll << j);
          P[j+1] = p[j]/(1ll << j);
        }
        DP[0] += (1-1.0l/(1ll << j))*dp[j];
        P[0] += (1-1.0l/(1ll << j))*p[j];
      }
      swap(dp,DP);
      swap(p,P);
    }
    long double res = 0;
    rep(i,50)if(dp[i] >= 0)res += dp[i];
    cout << res << "\n";
  }
  
  

  return 0;
}
accuracy: 1
time_ms: 230
memory_kb: 3512
final_rank: 7

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
#include <chrono>
#include <random>
#include <set>
#include <utility>
#include <array>
#include <bitset>
#include <unordered_set>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n, n) {
        vector<vector<double>> dp(n+1, vector<double>(50, -1));
        vector<double> p(50); p[0] = 1;
        for (int i = 1; i < 50; ++i) {
            p[i] = p[i-1]/2;
        }
        auto cal = [&](auto cal, int i, int j) -> double {
            if (j >= 50) return cal(cal,i+1,0);
            if (i >= n) return 0;
            if (dp[i][j] != -1) return dp[i][j];
            double P = p[j];
            dp[i][j] = P*(1+cal(cal,i+1,j+1))+(1-P)*(cal(cal,i+1,0));
            return dp[i][j];
        };
        printf("%.9f\n", cal(cal,0,0));
    }
}
accuracy: 1
time_ms: 250
memory_kb: 55336
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

typedef long long ll; typedef unsigned long long ull;
const int inf = 1e9; const ll llnf = 4e18;

template< class Tp > void chkmax( Tp &x , Tp y ) { x = max( x , y ); }
template< class Tp > void chkmin( Tp &x , Tp y ) { x = min( x , y ); }

void solve( ) {
	const int V = 1e5 , U = 100;
	vector< double > invpow2( V + 1 ); invpow2[0] = 1; for( int i = 1; i <= V; i ++ ) invpow2[i] = invpow2[i - 1] * 0.5;

	vector< vector< double > > f( V + 1 , vector< double >( U + 1 ) ); f[1][1] = 1;
	for( int i = 2; i <= V; i ++ ) for( int j = 0; j <= U; j ++ ) {
		if( j + 1 <= U ) f[i][j + 1] += f[i - 1][j] * ( invpow2[j] );
		f[i][0] += f[i - 1][j] * ( 1 - invpow2[j] );
	}

	vector< double > g( V + 1 );
	for( int i = 1; i <= V; i ++ ) { g[i] = g[i - 1]; for( int j = 1; j <= U; j ++ ) g[i] += f[i][j]; }

	int n; while( cin >> n && n ) cout << fixed << setprecision( 10 ) << g[n] << "\n";
}

int main( ) {
	ios::sync_with_stdio( 0 ), cin.tie( 0 ), cout.tie( 0 );
	int T = 1; while( T -- ) solve( ); return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 86604
final_rank: 16

code_snippet: /**
 * 百夜の悲しき、常闇に。
 * カヒコの来世を、統神に祷む。
*/

#include <bits/stdc++.h>
using namespace std;

#define inl inline
template <typename T> inl bool read (T &x) {
	x = 0; int f = 1; char c = getchar ();
	for (; c != EOF && !isdigit (c); c = getchar ())
		if (c == '-') f = -1;
	if (c == EOF) return 0;
	for (; c != EOF && isdigit (c); c = getchar ())
		x = (x<<1) + (x<<3) + (c^48);
	x *= f; return 1;
}
template <typename T, typename... Targs>
inl bool read (T &x, Targs&... args) {
	return read (x) && read (args...); }
template <typename T> void print (T x) {
	if (x < 0) putchar ('-'), x = -x;
	if (x > 9) print (x / 10);
	putchar ('0' + x % 10);
}
template <typename T, typename... Targs>
inl void print (T x, Targs... args) {
	print (x), putchar (' '), print (args...); }

#define newl putchar('\n')
typedef long long ll;
// typedef unsigned long long ull;
// typedef __int128 lll;
// typedef long double llf;
typedef pair <int, int> pint;
#define fst first
#define scd second
#define all(p) begin (p), end (p)
#define empb emplace_back
using comp = complex <double>;
using vcomp = vector <comp>;

constexpr int N = 1e5 + 10, G = 1<<18;
int n; double h[G], g[G]; vcomp f;

inl void butterfly (vcomp &f, int l) {
	static int tr[G], last;
	if (last != l) { last = l;
		for (int i = 1; i < 1<<l; ++i)
			tr[i] = tr[i>>1]>>1|(i & 1)*(1<<l-1);
	}
	for (int i = 1; i < 1<<l; ++i)
		if (tr[i] < i) swap (f[i], f[tr[i]]);
}
template <bool rev>
inl void FFT (vcomp &f, int l) {
	f.resize (1<<l, 0); butterfly (f, l);
	for (int len = 2; len <= 1<<l; len <<= 1) {
		const comp w_n = exp (M_PI/len*2i);
		comp g, h, w = 1;
		for (int st = 0; st < 1<<l; st += len, w = 1)
			for (int i = st; i < st+len/2; ++i, w *= w_n)
				g = f[i], h = f[i + len/2] * w,
				f[i] = g + h, f[i + len/2] = g - h;
	}
	if (!rev) return;
	reverse (begin (f) + 1, end (f));
	for (auto &x : f) x /= 1<<l;
}
#define clog2(x) (int) ceil (log2 (x))

inl vcomp imple () {
	vcomp f { 0 }, _g, invg { -1 }, _h;
	for (int w = 1; (1<<w-1) < 1e5; ++w) {
		_g = vcomp (g, g + (1<<w)),
		_h = vcomp (h, h + (1<<w));
		FFT <0> (f, w + 1); FFT <0> (_g, w + 1);
		FFT <0> (_h, w + 1); FFT <0> (invg, w + 1);
		for (int i = 0; i < 1<<w+1; ++i)
			f[i] = f[i] - (f[i] * _g[i] + _h[i]) * invg[i],
			invg[i] = 2.0 * invg[i] - invg[i] * invg[i] * _g[i];
		FFT <1> (f, w + 1);
		FFT <1> (invg, w + 1);
		fill (begin (f) + (1<<w), end (f), 0);
		fill (begin (invg) + (1<<w), end (invg), 0);
	}
	return f.resize (1e5 + 1), f;
}

int main () {
	/*  */
	double co, pre = 0;
	for (int i = 1; i <= 1e5; ++i)
		g[i] = co = pow (2, (i - 1) * (1-i/2.0))
			- pow (2, i * (1.0 - i) / 2),
		h[i] = (pre += co * (i-1)) + i * pow (2, (1.0-i)*i/2);
	g[0] = -1; f = imple ();

	while (read (n), n)
		printf ("%.8lf\n", real (f[n]));

	return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 27472
final_rank: 10

code_snippet: /**
 * 百夜の悲しき、常闇に。
 * カヒコの来世を、統神に祷む。
*/

#include <bits/stdc++.h>
using namespace std;

#define inl inline
template <typename T> inl bool read (T &x) {
	x = 0; int f = 1; char c = getchar ();
	for (; c != EOF && !isdigit (c); c = getchar ())
		if (c == '-') f = -1;
	if (c == EOF) return 0;
	for (; c != EOF && isdigit (c); c = getchar ())
		x = (x<<1) + (x<<3) + (c^48);
	x *= f; return 1;
}
template <typename T, typename... Targs>
inl bool read (T &x, Targs&... args) {
	return read (x) && read (args...); }
template <typename T> void print (T x) {
	if (x < 0) putchar ('-'), x = -x;
	if (x > 9) print (x / 10);
	putchar ('0' + x % 10);
}
template <typename T, typename... Targs>
inl void print (T x, Targs... args) {
	print (x), putchar (' '), print (args...); }

#define newl putchar('\n')
typedef long long ll;
// typedef unsigned long long ull;
// typedef __int128 lll;
// typedef long double llf;
typedef pair <int, int> pint;
#define fst first
#define scd second
#define all(p) begin (p), end (p)
#define empb emplace_back
using comp = complex <double>;
using vcomp = vector <comp>;

constexpr int N = 1e5 + 10, G = 1<<17;
int n; comp f[N], g[N]; double h[N];

inl void butterfly (vcomp &f, int l) {
	static int tr[G], last;
	if (last != l) { last = l;
		for (int i = 1; i < 1<<l; ++i)
			tr[i] = tr[i>>1]>>1|(i & 1)*(1<<l-1);
	}
	for (int i = 1; i < 1<<l; ++i)
		if (tr[i] < i) swap (f[i], f[tr[i]]);
}
template <bool rev>
inl void FFT (vcomp &f, int l) {
	f.resize (1<<l, 0); butterfly (f, l);
	for (int len = 2; len <= 1<<l; len <<= 1) {
		const comp w_n = exp (M_PI/len*2i);
		comp g, h, w = 1;
		for (int st = 0; st < 1<<l; st += len, w = 1)
			for (int i = st; i < st+len/2; ++i, w *= w_n)
				g = f[i], h = f[i + len/2] * w,
				f[i] = g + h, f[i + len/2] = g - h;
	}
	if (!rev) return;
	reverse (begin (f) + 1, end (f));
	for (auto &x : f) x /= 1<<l;
}
#define clog2(x) (int) ceil (log2 (x))

inl vcomp cyc_convo (const vcomp &f, const vcomp &g) {
	int n = max (f.size (), g.size ()), l = clog2 (n);
	vcomp _f = f, _g = g;
	FFT <0> (_f, l), FFT <0> (_g, l);
	for (int i = 0; i < 1<<l; ++i) _f[i] *= _g[i];
	FFT <1> (_f, l);
	return _f.resize (n), _f;
}

void cdq_dac (int l, int r) {
	if (l == r) { f[l] += h[l]; return; }
	int mid = l + r >> 1;
	cdq_dac (l, mid);
	vcomp _f (f + l, f + mid + 1),
		_g (g + 1, g + r-l+1);
	_g = cyc_convo (_f, _g);
	for (int i = mid + 1; i <= r; ++i)
		f[i] += _g[i-l-1];
	cdq_dac (mid + 1, r);
}

int main () {
	/*  */
	double co, pre = 0;
	for (int i = 1; i <= 1e5; ++i)
		g[i] = co = pow (2, (i - 1) * (1-i/2.0))
			- pow (2, i * (1.0 - i) / 2),
		h[i] = (pre += co * (i-1)) + i * pow (2, (1.0-i)*i/2);
	cdq_dac (0, 1e5);
	while (read (n), n)
		printf ("%.8lf\n", real (f[n]));

	return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 16392
final_rank: 9

code_snippet: #ifndef HIDDEN_IN_VS // 折りたたみ用

// 警告の抑制
#define _CRT_SECURE_NO_WARNINGS

// ライブラリの読み込み
#include <bits/stdc++.h>
using namespace std;

// 型名の短縮
using ll = long long; // -2^63 ～ 2^63 = 9 * 10^18（int は -2^31 ～ 2^31 = 2 * 10^9）
using pii = pair<int, int>;	using pll = pair<ll, ll>;	using pil = pair<int, ll>;	using pli = pair<ll, int>;
using vi = vector<int>;		using vvi = vector<vi>;		using vvvi = vector<vvi>;
using vl = vector<ll>;		using vvl = vector<vl>;		using vvvl = vector<vvl>;
using vb = vector<bool>;	using vvb = vector<vb>;		using vvvb = vector<vvb>;
using vc = vector<char>;	using vvc = vector<vc>;		using vvvc = vector<vvc>;
using vd = vector<double>;	using vvd = vector<vd>;		using vvvd = vector<vvd>;
template <class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
using Graph = vvi;

// 定数の定義
const double PI = acos(-1);
const vi DX = { 1, 0, -1, 0 }; // 4 近傍（下，右，上，左）
const vi DY = { 0, 1, 0, -1 };
int INF = 1001001001; ll INFL = 4004004004004004004LL;
double EPS = 1e-16;

// 入出力高速化
struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } } fastIOtmp;

// 汎用マクロの定義
#define all(a) (a).begin(), (a).end()
#define sz(x) ((int)(x).size())
#define lbpos(a, x) (int)distance((a).begin(), std::lower_bound(all(a), x))
#define ubpos(a, x) (int)distance((a).begin(), std::upper_bound(all(a), x))
#define Yes(b) {cout << ((b) ? "Yes\n" : "No\n");}
#define rep(i, n) for(int i = 0, i##_len = int(n); i < i##_len; ++i) // 0 から n-1 まで昇順
#define repi(i, s, t) for(int i = int(s), i##_end = int(t); i <= i##_end; ++i) // s から t まで昇順
#define repir(i, s, t) for(int i = int(s), i##_end = int(t); i >= i##_end; --i) // s から t まで降順
#define repe(v, a) for(const auto& v : (a)) // a の全要素（変更不可能）
#define repea(v, a) for(auto& v : (a)) // a の全要素（変更可能）
#define repb(set, d) for(int set = 0; set < (1 << int(d)); ++set) // d ビット全探索（昇順）
#define repp(a) sort(all(a)); for(bool a##_perm = true; a##_perm; a##_perm = next_permutation(all(a))) // a の順列全て（昇順）
#define smod(n, m) ((((n) % (m)) + (m)) % (m)) // 非負mod
#define uniq(a) {sort(all(a)); (a).erase(unique(all(a)), (a).end());} // 重複除去
#define EXIT(a) {cout << (a) << endl; exit(0);} // 強制終了

// 汎用関数の定義
template <class T> inline ll pow(T n, int k) { ll v = 1; rep(i, k) v *= n; return v; }
template <class T> inline bool chmax(T& M, const T& x) { if (M < x) { M = x; return true; } return false; } // 最大値を更新（更新されたら true を返す）
template <class T> inline bool chmin(T& m, const T& x) { if (m > x) { m = x; return true; } return false; } // 最小値を更新（更新されたら true を返す）

// 演算子オーバーロード
template <class T, class U> inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template <class T> inline istream& operator>>(istream& is, vector<T>& v) { repea(x, v) is >> x; return is; }
template <class T> inline vector<T>& operator--(vector<T>& v) { repea(x, v) --x; return v; }
template <class T> inline vector<T>& operator++(vector<T>& v) { repea(x, v) ++x; return v; }

// 手元環境（Visual Studio）
#ifdef _MSC_VER
#include "local.hpp"
// 提出用（gcc）
#else
inline int popcount(int n) { return __builtin_popcount(n); }
inline int popcount(ll n) { return __builtin_popcountll(n); }
inline int lsb(int n) { return n != 0 ? __builtin_ctz(n) : -1; }
inline int lsb(ll n) { return n != 0 ? __builtin_ctzll(n) : -1; }
inline int msb(int n) { return n != 0 ? (31 - __builtin_clz(n)) : -1; }
inline int msb(ll n) { return n != 0 ? (63 - __builtin_clzll(n)) : -1; }
#define gcd __gcd
#define dump(...)
#define dumpel(v)
#define dump_list(v)
#define input_from_file(f)
#define output_to_file(f)
#define Assert(b) { if (!(b)) while (1) cout << "OLE"; }
#endif

#endif // 折りたたみ用


////--------------AtCoder 専用--------------
//#include <atcoder/all>
//using namespace atcoder;
//
//using mint = modint1000000007;
////using mint = modint998244353;
////using mint = modint; // mint::set_mod(m);
//
//istream& operator>>(istream& is, mint& x) { ll x_; is >> x_; x = x_; return is; }
//ostream& operator<<(ostream& os, const mint& x) { os << x.val(); return os; }
//using vm = vector<mint>; using vvm = vector<vm>; using vvvm = vector<vvm>;
////----------------------------------------


int main() {
//	input_from_file("input.txt");
//	output_to_file("output.txt");

	while (true) {
		int n;
		cin >> n;

		if (n == 0) exit(0);

		// dp[i][j] : あと i 日で，いま j 日連続弁当を入手しているときの期待値
		vvd dp(n + 1 , vd(30));

		repi(i, 1, n) rep(j, 30) {
			double p = 1 / pow(2, 1. * j);

			// 弁当を入手出来る場合
			if (j < 29) dp[i][j] += (dp[i - 1][j + 1] + 1) * p;

			// 弁当を入手出来ない場合
			dp[i][j] += dp[i - 1][0] * (1 - p);
		}
		dumpel(dp);

		cout << dp[n][0] << endl;
	}
}
accuracy: 1
time_ms: 490
memory_kb: 31032
final_rank: 15

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

long double power(const long double base, const int exp) {
	switch (exp) {
	case 0: return 1;
	case 1: return base;
	default: return power(base * base, exp / 2) * power(base, exp % 2);
	}
}
long double cal_estimated(const int current, const int success, std::vector<std::vector<long double>>& memo) {
	if (current == memo.size()) return 0;
	if (success >= 30) return cal_estimated(current + 1, 0, memo);
	if (memo[current][success] >= 0) return memo[current][success];
	return memo[current][success] = power(0.5, success) * (cal_estimated(current + 1, success + 1, memo) + 1) + (1 - power(0.5, success)) * cal_estimated(current + 1, 0, memo);
}

int main() {
	constexpr int max_day = 100000;
	std::vector<std::vector<long double>> memo(max_day, std::vector<long double>(30, -1));
	for (auto i = 1; i < memo.size(); i += 100) cal_estimated(max_day - i, 0, memo);
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::cout << std::setprecision(5) << std::fixed << cal_estimated(max_day - n, 0, memo) << '\n';
	}
}
accuracy: 1
time_ms: 250
memory_kb: 53380
final_rank: 13

code_snippet: #include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

int n;
double dp[100005][35];

int main(void)
{
	while(1){
		cin >> n;
		if(n == 0) break;
		
		for(int i = n-1; i >= 0; i--){
			for(int j = 0; j < 35; j++){
				double p = pow(2, -j);
				dp[i][j] = (1-p) * dp[i+1][0];
				if(j+1 < 35) dp[i][j] += p * (dp[i+1][j+1]+1);
			}
		}
		printf("%.11f\n", dp[0][0]);
	}
	
	return 0;
}
accuracy: 1
time_ms: 720
memory_kb: 30592
final_rank: 18

code_snippet: #include <bits/stdc++.h>

const int maxn = 1e5 + 3, maxm = 12;

int n;
double dp[maxn][maxm], pr[maxn][maxm];

int main() {
    while(scanf("%d", &n) != EOF) {
        if(n == 0)
            return 0;
        memset(dp, 0, sizeof(dp[0]) * (n + 1));
        memset(pr, 0, sizeof(pr[0]) * (n + 1));
        pr[0][0] = 1.0;
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < maxm - 1; ++j) {
                dp[i + 1][j + 1] += (dp[i][j] + pr[i][j]) * pow(0.5, j);
                pr[i + 1][j + 1] += pr[i][j] * pow(0.5, j);
            }
            for(int j = 0; j < maxm; ++j) {
                dp[i + 1][0] += dp[i][j] * (1.0 - pow(0.5, j));
                pr[i + 1][0] += pr[i][j] * (1.0 - pow(0.5, j));
            }
        }
        printf("%.8f\n", std::accumulate(dp[n], dp[n] + maxm, 0.0));
    }
    return 0;
}
accuracy: 1
time_ms: 760
memory_kb: 22088
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}


const int M = 20;
double p[M];
double pp[M];

const int N = 100010;
double dp[N];
bool vis[N];

int n;
double dfs(int d){
    if(vis[d]) return dp[d];
    if(d==n) return 0;

    double ret = 0;
    for(int j=1; j<M-1; ++j){
        if(d+j+1<=n) ret += p[j]*(1-pp[j+1])*(j + dfs(d+j+1));
        if(d+j==n) ret += p[j]*(j+ dfs(d+j));
    }

    vis[d] = true;
    return dp[d] = ret;
}

int main(){
    p[1] = 1;
    pp[1] = 1;
    for(int i=2; i<M; ++i){
        pp[i] = pp[i-1]/2;
        p[i] = p[i-1]*pp[i];
    }

    while(cin >>n,n){
        fill(vis,vis+N,false);
        printf("%.10f\n", dfs(0));
    }
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 8716
final_rank: 2

code_snippet: #include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

double dp[300000][20];
double ans[300000];

int main(){
	dp[0][0]=1;
	double sum=0;
	rep(i,200000){
		ans[i]=sum;
		rep(j,15){
			if(dp[i][j]==0)continue;
			double p=1;rep(k,j)p*=0.5;
			sum+=p*dp[i][j];
			dp[i+1][j+1]+=dp[i][j]*p;
			dp[i+1][0]+=dp[i][j]*(1-p);
		}
	}
	int n;
	while(cin>>n,n){
		printf("%.12lf\n",ans[n]);
	}
}
accuracy: 1
time_ms: 10
memory_kb: 35820
final_rank: 8

code_snippet: // includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// }}}
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 1e5;
const int C = 70;

double dp[N + 1]; // i日目が「食べていない日」の最終日であるときのそれ
double p[N + 1];
double ans[N + 1];

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  double p2[C], p2s[C];
  p2s[0] = p2[0] = 1;
  for(int i = 1; i < C; i++) p2[i] = p2[i-1] * .5;
  for(int i = 1; i < C; i++) p2s[i] = p2[i] * p2s[i-1];

  p[0] = 1;

  for(int i = 1; i <= N; i++) {
    for(int j = 1; j < C && i-j-1 >= 0; j++) if(p[i-j-1] > 0) {
      // j日間食べ続け，最後に食べない
      p[i] += p[i-j-1] * p2s[j-1] * (1 - p2[j]);
      dp[i] += (dp[i-j-1] / p[i-j-1] + j) * p[i-j-1] * p2s[j-1] * (1 - p2[j]);
      // j日間食べ続け，最後に食べない
      ans[i] += (dp[i-j-1] / p[i-j-1] + j + 1) * p[i-j-1] * p2s[j];
    }
    ans[i] += dp[i];
    if(p[i-1] > 0) ans[i] += (dp[i-1] / p[i-1] + 1) * p[i-1];
  }

  int n;
  cout << fixed << setprecision(10);
  while(cin >> n, n) {
    cout << ans[n] << "\n";
  }
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 5568
final_rank: 3

code_snippet: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 100010;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

void solve(void){


	int M = 100, N;
	vecd ps(M, 1);

	rep(M-1, i)
	{
		ps[i+1] = ps[i] / 2;
	}

	//cout << ps << endl;

	while(cin >> N && N)
	{
		matd dp(N+1, vecd (M, 0));

		dp[0][0] = 1;

		double ans = 0;

		rep(N, n) rep(M, m)
		{
			if (m == M-1)
			{
				dp[n+1][0] += dp[n][m];
				ans += dp[n][m] * m;
				continue;
			}

			double p = ps[m];

			dp[n+1][m+1] += dp[n][m] * p;
			dp[n+1][0] += dp[n][m] * (1-p);
			ans += dp[n][m] * (1-p) * m;
		}

		rep(M, m)
		{
			ans += dp[N][m] * m;
		}

		cout << fixed << setprecision(3) << ans << endl;

	}


}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
accuracy: 1
time_ms: 290
memory_kb: 84996
final_rank: 19

code_snippet: // 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const int MAX_K = 15;
double dp[2][MAX_K], ans[100010];

signed main() {
    dp[0][1] = ans[1] = 1.0;

    rep(i,0,100000) {
        int cur = i%2, nxt = cur^1;
        rep(j,0,MAX_K) {
            double P = pow(0.5, j);
            if(j+1 < MAX_K) dp[nxt][j+1] += P * dp[cur][j];
            dp[nxt][0] += (1 - P) * dp[cur][j];
        }
        fill(dp[cur], dp[cur] + MAX_K, 0.0);
        ans[i+2] = ans[i+1] + (1 - dp[nxt][0]);
    }
    
    while(1) {
        int N; scanf("%lld", &N);
        if(N == 0) break;
        printf("%.12f\n", ans[N]);
    }
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4132
final_rank: 1

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;
 
 
double dp[100010][50];
double ans[100010];
 
 
double pow2(int i){
    return pow(2, -i);
}
 
 
void makeDP(){
    dp[1][1] = 1;
    ans[1] = 1;
 
    rep(i, 1, 100005){
        rep(j, 0, 49){
            dp[i+1][j+1] = dp[i][j]*pow2(j);
            ans[i+1] += dp[i+1][j+1];
            dp[i+1][0] += dp[i][j]-dp[i+1][j+1];
        }
        ans[i+1] += ans[i];
    }
}
 
 
int main(){
    int n;
 
    makeDP();
     
    while(cin >> n, n) cout << fixed << ans[n] << endl;
 
    return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 43220
final_rank: 11

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;
 
 
double dp[100010][50]; //DPテーブル(dp[日数][確率の指数]) 多分指数は100も必要ない
double ans[100010]; //n日間の間に弁当を獲得できる回数の期待値
 
 
double pow2(int i){ //2^(-i)
    return pow(2, -i);
}
 
 
void makeDP(){ //DPテーブルを作成しansへ期待値を書き込む
    dp[1][1] = 1;
    ans[1] = 1;
 
    rep(i, 1, 100005){
        rep(j, 0, 49){
            dp[i+1][j+1] = dp[i][j]*pow2(j);
            ans[i+1] += dp[i+1][j+1]; //i+1日目に獲得できる期待値を足しておく
            dp[i+1][0] += dp[i][j]-dp[i+1][j+1];
        }
        ans[i+1] += ans[i]; //前日の期待値を足す
    }
}
 
 
int main(){
    int n;
 
    makeDP();
     
    while(cin >> n, n) cout << fixed << ans[n] << endl;
 
    return 0;
}
accuracy: 1
time_ms: 250
memory_kb: 43084
final_rank: 12

code_snippet: #include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;


double dp[100010][100];
double ans[100010];


double pow2(int i){
	return pow(2, -i);
}


void makeDP(){
	dp[1][1] = 1;
	ans[1] = 1;

	rep(i, 1, 100005){
		rep(j, 0, 99){
			double e = dp[i][j]*pow2(j);
			dp[i+1][j+1] += e;
			ans[i+1] += e;
			dp[i+1][0] += dp[i][j]-e;
		}
		ans[i+1] += ans[i];
	}
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n;

	makeDP();
	
	while(cin >> n, n) cout << fixed << ans[n] << endl;

	return 0;
}
accuracy: 1
time_ms: 510
memory_kb: 82308
final_rank: 20

code_snippet: #include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
double dp[2][200];
double ans[200000];
double p[200];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  p[0] = 1;
  rep(i, 100-1) p[i+1] = p[i]*0.5;
  int L = 150000;
  int T = 150;
  dp[0][0] = 1;
  ans[0] = 0;
  double base = 0;
  rep(i, L) {
    rep(j, T) dp[1][j] = 0;
    dp[1][1] = dp[0][0];
    for (int j=1; j<T-1; j++) {
      // succ
      dp[1][j+1] += dp[0][j] * p[j];
      // fail
      dp[1][0] += (dp[0][j] * (1.0-p[j]));
      base += (dp[0][j] * (1.0-p[j])) * j;
    }
    ans[i+1] = base;
    rep(j, T) ans[i+1] += dp[1][j]*j;
    swap(dp[0], dp[1]);
  }

  while (cin >> N) {
    if (N == 0) break;
    cout << fixed << setprecision(20) << ans[N] << "\n";
  }
  return 0;
}
accuracy: 1
time_ms: 110
memory_kb: 4420
final_rank: 5