func_code_string: #include <bits/stdc++.h>   using namespace std;   template <typename T>   inline bool chkmin(T &a, const T &b) {     return a > b ? a = b, 1 : 0;   }   template <typename T>   inline bool chkmax(T &a, const T &b) {     return a < b ? a = b, 1 : 0;   }   const int oo = 0x3f3f3f3f;   const int max0 = 50, maxn = 1000;   int n, first;   double p, q;   double a[maxn + 5][max0 + 5];   double b[maxn + 5][max0 + 5];   double dp[maxn + 5][max0 + 5];   int main() {     scanf( %d%d , &n, &first);     p = first / 1e9, q = 1 - p;     for (int i = (1), _end_ = (maxn + 1); i < _end_; ++i)       for (int j = (1), _end_ = (max0); j < _end_; ++j) {         if (j == 1) a[i][j] += p;         if (j == 2) a[i][j] += q, b[i][j] += q;         a[i][j] += a[i - 1][j - 1] * a[i][j - 1];         b[i][j] += a[i - 1][j - 1] * b[i][j - 1];       }     for (int i = maxn; i >= 1; --i)       for (int j = (1), _end_ = (max0); j < _end_; ++j)         a[i][j] *= 1 - a[i - 1][j], b[i][j] *= 1 - a[i - 1][j];     for (int i = (1), _end_ = (max0); i < _end_; ++i) dp[maxn][i] = i;     for (int i = maxn - 1; i >= 0; --i)       for (int j = (1), _end_ = (max0); j < _end_; ++j) {         double sum = 0;         for (int k = (1), _end_ = (max0); k < _end_; ++k) {           if (j == k) continue;           int pos = maxn - i;           if (j == 1)             dp[i][j] += b[pos][k] * dp[i + 1][k], sum += b[pos][k];           else if (j > k)             dp[i][j] += a[pos][k] * dp[i + 1][k], sum += a[pos][k];         }         (dp[i][j] /= sum) += j;       }     double ans = 0;     if (n <= maxn)       for (int i = (1), _end_ = (max0); i < _end_; ++i)         ans += a[n][i] * dp[maxn - n + 1][i];     else {       double sum0 = 0, sum1 = 0;       for (int i = (1), _end_ = (max0); i < _end_; ++i)         sum0 += a[maxn][i] * dp[0][i];       for (int i = (1), _end_ = (max0); i < _end_; ++i)         sum1 += a[maxn - 1][i] * dp[1][i];       ans = sum1 + (sum0 - sum1) * (n - maxn + 1);     }     printf( %.15f n , ans);     return 0;   }   