Click Here to go back to the homepage.

Jewelry Box Solution:


#include <bits/stdc++.h>

using namespace std;

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int boxes;
    cin >> boxes;
    while(boxes--){
        double x, y, h;
        cin >> x >> y;
        h = (y + x - sqrt((y+x) * (y+x) - 3 * x * y)) / 6;
        cout << fixed << setprecision(7);
        cout << (x - 2 * h) * (y - 2 * h) * h << endl;
    }

    return 0;
}