#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; struct fast_io { fast_io() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(5); } } fastIOtmp; #include using Bint = boost::multiprecision::cpp_int; int main() { // 係数列を前もって計算しておく. int N = 200; vector> f(N + 1); f[0] = vector{ 1 }; for (int n = 1; n <= N; ++n) { f[n].resize(n + 1); for (int i = 0; i < n; ++i) f[n][i + 1] -= 2 * n * f[n - 1][i]; for (int i = 1; i < n; ++i) { f[n][i - 1] += i * f[n - 1][i]; f[n][i + 1] += i * f[n - 1][i]; } for (int i = 0; i < n; ++i) f[n][i] /= n; } vector pow100000(N + 1); pow100000[0] = 1; for (int n = 0; n < N; ++n) pow100000[n + 1] = pow100000[n] * 100000; for (int n = 1; n <= N; ++n) for (int i = 0; i <= n; ++i) f[n][i] *= pow100000[n - i]; int t; cin >> t; // クエリ先読み vector nXjs(t); for (int j = 0; j < t; ++j) { long long n; double x; cin >> n >> x; long long X_int((long long)(x * 100000 + (x > 0 ? 0.1 : -0.1))); nXjs[j] = (n << (18 + 17)) | (X_int << 17) | (long long)j; } // クエリの処理順をランダムにする. mt19937_64 mt(0); shuffle(nXjs.begin(), nXjs.end(), mt); vector res(t); // 答えのメモ vector> sol(201); for (auto nXj : nXjs) { int j = (int)(nXj & ((1LL << 17) - 1)); nXj >>= 17; int X_int = (int)(nXj & ((1LL << 18) - 1)); int n = (int)(nXj >> 18); if (n == 0) { res[j] = 1; continue; } // メモした答えの線形補間 auto nit = sol[n].lower_bound(X_int); if (nit != sol[n].begin() && nit != sol[n].end()) { auto pit = prev(nit); auto [pi, pv] = *pit; auto [ni, nv] = *nit; // メモした答えの幅 40 以下の区間に挟まれているなら内挿補間する if (ni - pi <= 40) { float val = pv + (nv - pv) / (ni - pi) * (X_int - pi); res[j] = val; continue; } } Bint X = X_int; Bint X2 = X * X; // ここが遅い・・・はずなのだが思ってるよりずっと速い Bint Res = 0; for (int i = n; i >= 0; i -= 2) { Res *= X2; Res += f[n][i]; } if (n & 1) Res *= X; float val = static_cast(Res / pow100000[n - 1]); float x = X_int / 100000.f; val *= pow(x * x + 1, -n / 2.f) / 100000.f; res[j] = val; sol[n][X_int] = val; } for (int j = 0; j < t; ++j) cout << res[j] << "\n"; }