if (u == 1) { ll upx = limitx ? x : 1; ll upy = limity ? y : 1; for (ll i = 0; i <= upx; i++) { for (ll j = 0; j <= upy; j++) { if (!(i == 1 && j == 1)) { res++; } } }
} else { ll high = 1 << (u - 1); // 1000000 1在第u位 ll mask = high | (high - 1);
ll nextMask = mask >> 1;
// x=0, y=0 res += dfs(u - 1, limitx && x < nextMask, limity && y < nextMask, x & nextMask, y & nextMask);
// x=0, y=1 if (!limity || y >= high) { res += dfs(u - 1, limitx && x < nextMask, limity, x & nextMask, y & nextMask); } // x=1, y=0 if (!limitx || x >= high) { res += dfs(u - 1, limitx, limity && y < nextMask, x & nextMask, y & nextMask); } }
ll high = 1 << (u - 1); // 1000000 1在第u位 ll mask = high | (high - 1);
ll nextMask = mask >> 1;
// x=0 y=0 res += getAns(u - 1, limitx && x < nextMask, limity && y < nextMask, x & nextMask, y & nextMask);
// x=0, y=1 if (!limity || y >= high) { ll count = dfs(u - 1, limitx && x < nextMask, limity, x & nextMask, y & nextMask); // prllf("%d*%d\n", u, count); res += u * count; } // x=1, y=0 if (!limitx || x >= high) { ll count = dfs(u - 1, limitx, limity && y < nextMask, x & nextMask, y & nextMask); // prllf("%d*%d\n", u, count); res += u * count; }
intmain(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; double ans = 0; dp[1] = 1; ans += 2 * m * dp[1]; for (int j = 2; j <= 2 * m; ++j) { double tmp = min(2.0, pi / m * 1 * min(j - 1, 2 * m + 1 - j)); dp[1] += tmp; ans += m * tmp; }
for (int i = 2; i <= n; ++i) { dp[i] = dp[i - 1] + (i - 1) * (2 * m) + 1; ans += 2 * m * dp[i]; for (int j = 2; j <= 2 * m; ++j) { double tmp = min(2.0 * i, pi / m * i * min(j - 1, 2 * m + 1 - j)); dp[i] += tmp; ans += m * tmp; } }
if(m == 1) { ans -= n * (n + 1); } printf("%.10f\n", ans); }