#include #include #include #include #include // Use long double for maximum precision, as the areas can be very large. using ldouble = long double; /** * @brief Calculates the area of a regular n-sided polygon. * * The area is derived from the perimeter, which is determined by the total time 't', * the time to make a marker 'm', and the number of vertices 'n'. * * @param n The number of vertices (sides) of the polygon. * @param m The time cost to make a single marker. * @param t The total available time. * @return The maximum possible area for an n-sided polygon, as a long double. */ ldouble calculate_area(long long n, long long m, long long t) { // A polygon must have at least 3 vertices. if (n < 3) { return 0.0L; } // The time to make all markers cannot exceed the total time. if ((__int128)n * m >= t) { return 0.0L; } // Calculate the remaining time for walking, which equals the perimeter. // Cast to long double to prevent overflow and maintain precision. ldouble perimeter = (ldouble)t - (ldouble)n * m; // Area of a regular n-gon with perimeter P is: A = P^2 / (4 * n * tan(pi/n)) ldouble tan_val = tan(M_PIl / n); if (tan_val == 0.0L) { // Avoid division by zero, though unlikely for n>=3 return 0.0L; } return (perimeter * perimeter) / (4.0L * n * tan_val); } /** * @brief Solves a single test case for the Enclosure problem. */ void solve() { long long m, t; std::cin >> m >> t; // Calculate the maximum possible number of vertices Pahom can make. long long n_max = t / m; // If it's not possible to make at least 3 markers, no polygon can be formed. if (n_max < 3) { std::cout << std::fixed << std::setprecision(15) << 0.0L << std::endl; return; } // The area function A(n) is unimodal, so we can use ternary search to find // the integer 'n' that maximizes the area. long long low = 3; long long high = n_max; while (high - low >= 3) { long long m1 = low + (high - low) / 3; long long m2 = high - (high - low) / 3; if (calculate_area(m1, m, t) < calculate_area(m2, m, t)) { // If A(m1) is smaller, the maximum is likely in the range [m1, high] low = m1; } else { // Otherwise, it's likely in [low, m2] high = m2; } } // After ternary search, the optimal 'n' is in the small range [low, high]. // We do a final linear scan to find the true maximum. ldouble max_area = 0.0L; for (long long n = low; n <= high; ++n) { max_area = std::max(max_area, calculate_area(n, m, t)); } std::cout << std::fixed << std::setprecision(15) << max_area << std::endl; } int main() { // Fast I/O std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int num_cases; std::cin >> num_cases; while (num_cases--) { solve(); } return 0; }