Johnny needs to make a rectangular box for his physics class project. He has bought P cm of wire and S cm^{2} of special paper. He would like to use all the wire (for the 12 edges) and paper (for the 6 sides) to make the box.
What is the largest volume of the box that Johnny can make?

------ Input ------ 

The first line contains t, the number of test cases (about 10). Then t test cases follow.

Each test case contains two integers P and S in a line (1 ≤ P ≤ 40000, 1 ≤ S ≤ 20000). You may assume that there always exists an optimal solution for the given input cases.

------ Output ------ 

For each test case, print a real number that is the largest volume of the box that Johnny can make, rounded to two decimal places.

----- Sample Input 1 ------ 
2
20 14
20 16
----- Sample Output 1 ------ 
3.00
4.15
----- explanation 1 ------ 
First case: the dimensions of the largest box may be 3, 1 and 1.
Second case: the dimensions of the largest box may be 7/3, 4/3 and 4/3.

Difficulty: EASY
Tags: Geometry

Mathematics

Starter code:

Solutions:
for _ in range(int(input())):
	(p, s) = map(int, input().split())
	y2 = (p - (p ** 2 - 4 * 6 * s) ** (1 / 2)) / 12
	x2 = (s - 2 * y2 * y2) / (4 * y2)
	first = round(x2 * y2 * y2, 2)
	print(first)


from math import sqrt
t = int(input())
for i in range(t):
	(p, a) = map(int, input().split())
	l = (p - sqrt(p * p - 24 * a)) / 12
	v = l * (a / 2.0 - l * (p / 4.0 - l))
	print(round(v, 2))


import math
t = int(input())
for i in range(t):
	(P, S) = map(int, input().split())
	h = (P - math.sqrt(P * P - 24 * S)) / 12
	volume = S * h / 2 - h * h * P / 4 + h * h * h
	print('%.2f' % volume)


from math import sqrt
try:
	for _ in range(int(input())):

		def maxVol(P, A):
			l = (P - sqrt(P * P - 24 * A)) / 12
			V = l * (A / 2.0 - l * (P / 4.0 - l))
			return V
		(P, A) = map(int, input().split())
		print(round(maxVol(P, A), 2))
except:
	pass


for tc in range(int(input())):
	(p, s) = map(int, input().split())
	V = p ** 3 / 1728.0 - p * (p ** 2 / 24.0 - s) / 24.0 + (p ** 2 / 24.0 - s) ** 1.5 * 6 ** 0.5 / 18
	print('%.2f' % V)


for i in range(int(input())):
	(p, s) = map(int, input().split())
	b1 = (p + (p ** 2 - 24 * s) ** 0.5) / 12
	h1 = b1
	l1 = p / 4 - 2 * b1
	b2 = (p - (p ** 2 - 24 * s) ** 0.5) / 12
	h2 = b2
	l2 = p / 4 - 2 * b2
	vol = max(l1 * b1 * h1, l2 * b2 * h2)
	print(round(vol, 2))


from math import sqrt
T = int(input())
for i in range(T):
	(P, S) = map(int, input().split())
	h = (P - sqrt(P ** 2 - 24 * S)) / 12
	V = S * h / 2 - h ** 2 * (P / 4 - h)
	print(round(V, 2))


from math import sqrt

def answer(P, A):
	l = (P - sqrt(P * P - 24 * A)) / 12
	V = l * (A / 2.0 - l * (P / 4.0 - l))
	return '%.2f' % V
for i in range(int(input())):
	(P, S) = map(int, input().split())
	print(answer(P, S))


t = int(input())
for i in range(t):
	(p, s) = map(int, input().split())
	y = (p - (p * p - 24 * s) ** 0.5) / 12
	x = (s - 2 * y * y) / (4 * y)
	print(round(x * y * y, 2))


from math import sqrt
t = int(input())
for i in range(t):
	x = input()
	P = int(x.split(' ')[0])
	S = int(x.split(' ')[1])
	b = (P - sqrt(P * P - 24 * S)) / 12
	v = b * (S / 2 - P * b / 4 + b * b)
	print(f'{v:.2f}')


from math import sqrt
for _ in range(int(input())):
	(P, A) = map(int, input().split())
	l = (P - sqrt(P * P - 24 * A)) / 12
	V = l * (A / 2 - l * (P / 4 - l))
	print(round(V, 2))


T = int(input())
for _ in range(T):
	(p, s) = input().split()
	p = int(p)
	s = int(s)
	length = (p - (p * p - 24 * s) ** 0.5) / 12
	volume = length * (s / 2.0 - length * (p / 4.0 - length))
	print('%.2f' % volume)


T = int(input())
for i in range(0, T):
	(p, s) = map(int, input().split())
	x = (p - (p ** 2 - 24 * s) ** 0.5) / 12
	h = (p - 8 * x) / 4
	print(round(x * x * h, 2))


import math
number_of_test_cases = int(input())
for t in range(0, number_of_test_cases):
	case = input().split()
	p = int(case[0])
	a = int(case[1])
	l = (p - math.sqrt(p ** 2 - 24 * a)) / 12
	v = l * (a / 2 - l * p / 4 + l ** 2)
	print(round(v, 2))


for t in range(int(input())):
	(P, S) = [int(x) for x in input().split()]
	l = (P / 2 - (P ** 2 / 4 - 6 * S) ** 0.5) / 6
	print(round(l * (S / 2 - l * (P / 4 - l)), 2))


import math
for _ in range(int(input())):
	(p, s) = map(int, input().split())
	h = (p - math.sqrt(p * p - 24 * s)) / 12
	v = s * h / 2 - h * h * p / 4 + h ** 3
	print('%.2f' % v)


t = int(input())
for T in range(t):
	(P, S) = input().split()
	(P, S) = (int(P), int(S))
	D = 0.25 * P * P - 6 * S
	h1 = 1 / 6 * (0.5 * P + D ** 0.5)
	h2 = 1 / 6 * (0.5 * P - D ** 0.5)
	V1 = 0.5 * S * h1 - 0.25 * P * h1 * h1 + h1 * h1 * h1
	V2 = 0.5 * S * h2 - 0.25 * P * h2 * h2 + h2 * h2 * h2
	V = max(V1, V2)
	print(round(V, 2))


import math
t = int(input())
for c in range(t):
	(p, s) = map(int, input().split())
	h = (p - math.sqrt(p * p - 24 * s)) / 12
	volume = s * h / 2 - h * h * p / 4 + h ** 3
	print('%.2f' % volume)


from math import sqrt
for _ in range(int(input())):
	(p, s) = map(int, input().split())
	p /= 4
	s /= 2
	if 3 * (p / 3) ** 2 <= s:
		print((p / 3) ** 3)
	else:
		c1 = (p + sqrt(p ** 2 - 3 * s)) / 3
		a1 = p - 2 * c1
		c2 = (p - sqrt(p ** 2 - 3 * s)) / 3
		a2 = p - 2 * c2
		v = max(a1 * c1 ** 2, a2 * c2 ** 2)
		print(round(v, 2))


from math import sqrt
for t in range(int(input())):
	(p, s) = map(int, input().split())
	l = (p - sqrt(p * p - 24 * s)) / 12
	v = l * (s / 2 - l * (p / 4 - l))
	print('{0:.2f}'.format(round(v, 2)))


from math import sqrt
for abhi in range(int(input())):
	(P, S) = map(int, input().split())
	l = (P - sqrt(P * P - 24 * S)) / 12
	V = l * (S / 2 - l * (P / 4 - l))
	print(round(V, 2))


import math
T = int(input())
for i in range(T):
	(P, S) = [int(ii) for ii in input().split()]
	xy = (P - math.sqrt(P ** 2 - 24 * S)) / 12
	z = (P + 2 * math.sqrt(P ** 2 - 24 * S)) / 12
	V = round(xy ** 2 * z, 2)
	print(format(V, '.2f'))


from math import sqrt
t = int(input())
for _ in range(t):
	(A, B) = map(int, input().split())
	V = (36 * A * B - A ** 3 + sqrt((A * A - 24 * B) ** 3)) / (12 * 72)
	print('{0:.2f}'.format(V))


T = int(input(''))
for i in range(T):
	(P, S) = [int(x) for x in input('').split()]
	x = (P - (P * P - 24 * S) ** 0.5) / 12
	V = x * S / 2 - x * x * P / 4 + x * x * x
	M = round(V, 2)
	print(M)


from sys import stdin, stdout
t = int(stdin.readline().rstrip())
while t > 0:
	(p, s) = map(int, stdin.readline().rstrip().split())
	h1 = (p - pow(pow(p, 2) - 24 * s, 0.5)) / 12
	h2 = (p + pow(pow(p, 2) - 24 * s, 0.5)) / 12
	l1 = p / 4 - 2 * h1
	l2 = p / 4 - 2 * h2
	v1 = l1 * h1 ** 2
	v2 = l2 * h2 ** 2
	if v1 > v2:
		print('{:0.2f}'.format(v1))
	else:
		print('{:0.2f}'.format(v2))
	t -= 1


import math
for z in range(int(input())):
	(a, b) = map(int, input().split())
	h = (a - math.sqrt(a * a - 24 * b)) / 12
	v = b * h / 2 - h * h * a / 4 + h ** 3
	print('%.2f' % v)


ujju = int(input())
for jyo in range(ujju):
	(d, w) = input().split()
	(d, w) = (int(d), int(w))
	n = 0.25 * d * d - 6 * w
	t1 = 1 / 6 * (0.5 * d + n ** 0.5)
	t2 = 1 / 6 * (0.5 * d - n ** 0.5)
	rtc = 0.5 * w * t1 - 0.25 * d * t1 * t1 + t1 * t1 * t1
	ac = 0.5 * w * t2 - 0.25 * d * t2 * t2 + t2 * t2 * t2
	mp = max(rtc, ac)
	print(round(mp, 2))


for _ in range(int(input())):
	(P, S) = map(int, input().split())
	l = (P - pow(P * P - 24 * S, 0.5)) / 12
	h = (P - 8 * l) / 4
	print('%.2f' % (h * l * l))


import math
t = int(input())
while t > 0:
	(a, b) = map(int, input().split())
	s = a - math.sqrt(a * a - 24 * b)
	s /= 12
	v = 0.0
	v = s * s * s + b * s / 2 - s * s * a / 4
	print('%.2f' % v)
	t -= 1


n = int(input())

def best_box(p, s):
	b1 = (p / 2 + (p ** 2 / 4 - 6 * s) ** (1 / 2)) / 6
	b2 = (p / 2 - (p ** 2 / 4 - 6 * s) ** (1 / 2)) / 6
	h1 = p / 4 - 2 * b1
	v1 = b1 ** 2 * h1
	h2 = p / 4 - 2 * b2
	v2 = b2 ** 2 * h2
	if v1 > v2:
		return '{:.2f}'.format(round(v1, 2))
	else:
		return '{:.2f}'.format(round(v2, 2))
for i in range(n):
	n = input()
	x = n.split()
	print(best_box(int(x[0]), int(x[1])))


from math import sqrt
for _ in range(int(input())):
	(p, s) = map(int, input().split())
	l = (p - sqrt(p * p - 24 * s)) / 12
	v = l * (s / 2.0 - l * (p / 4.0 - l))
	print(round(v, 2))


T = int(input())
for i in range(T):
	P = input().split()
	S = int(P[1])
	P = int(P[0])
	V = P ** 3 / 1728.0 - P * (P ** 2 / 24.0 - S) / 24.0 + (P ** 2 / 24.0 - S) ** 1.5 * 6 ** 0.5 / 18
	print('%.2f' % V)


for i in range(int(input())):
	(p, s) = map(int, input().split())
	h = (p - (p * p - 24 * s) ** (1 / 2)) / 12
	v = s * h / 2 - h * h * p / 4 + h ** 3
	print('%.2f' % v)


from math import sqrt
t = int(input())
for i in range(t):
	(P, A) = map(int, input().split())
	x = (P - sqrt(P ** 2 - 24 * A)) / 12
	y = P / 4 - 2 * x
	print(round(x ** 2 * y, 2))


import math as s
for i in range(int(input())):
	(l, m) = map(int, input().split())
	a = l / 4
	b = m / 2
	x = (2 * a + s.sqrt((2 * a) ** 2 - 12 * b)) / 6
	y = (2 * a - s.sqrt((2 * a) ** 2 - 12 * b)) / 6
	if 6 * x - 2 * a < 0:
		print('{:0.2f}'.format(b * x - x ** 2 * (a - x)))
	else:
		print('{:0.2f}'.format(b * y - y ** 2 * (a - y)))


for jj in range(int(input())):
	(p, s) = map(int, input().split())
	h = (p - (p * p - 24 * s) ** 0.5) / 12
	v = h * (s / 2 - h * (p / 4 - h))
	print('%.2f' % v)


a = int(input())
for i in range(a):
	(p, s) = map(int, input().split())
	b = -(-p + (p ** 2 - 24 * s) ** (1 / 2)) / 12
	c = (p - 8 * b) / 4
	v = c * b * b
	print(round(v, 2))


t = int(input())
import math
for t in range(t):
	(p, s) = map(int, input().split())
	d = p ** 2
	a = 8 * s * 4 / d - 1
	c = 8 * s / d
	b = 32 * s / d - 2
	r = (-b - math.sqrt(b ** 2 - 4 * a * c)) / (2 * a)
	x = p / (4 * (1 + 2 * r))
	y = x * r
	answer = x * y * y
	answer = round(answer, 2)
	print(answer)


from math import sqrt
t = int(input())
for ts in range(t):
	(perimeter, area) = map(int, input().split())
	l = (perimeter - sqrt(perimeter * perimeter - 24 * area)) / 12
	v = l * (area / 2.0 - l * (perimeter / 4.0 - l))
	print(round(v, 2))