CYLINDER - Cylinder

Using a sheet of paper and scissors, you can cut out two faces to form a cylinder in the following way:

  1. Cut the paper horizontally (parallel to the shorter side) to get two rectangular parts.
  2. From the first part, cut out a circle of maximum radius. The circle will form the bottom of the cylinder.
  3. Roll the second part up in such a way that it has a perimeter of equal length with the circle's circumference, and attach one end of the roll to the circle. Note that the roll may have some overlapping parts in order to get the required length of the perimeter.

Given the dimensions of the sheet of paper, can you calculate the biggest possible volume of a cylinder which can be constructed using the procedure described above?

Input Specification

The input consists of several test cases. Each test case consists of two numbers w and h (1 ≤ w ≤ h ≤ 100), which indicate the width and height of the sheet of paper.

The last test case is followed by a line containing two zeros.

Output Specification

For each test case, print one line with the biggest possible volume of the cylinder. Round this number to 3 places after the decimal point.

Sample Input

10 10
10 50
10 30
0 0

Sample Output

54.247
785.398
412.095

In the first case, the optimal cylinder has a radius of about 1.591549, in the second case, the optimal cylinder has a radius of 5, and in the third case, the optimal cylinder has a radius of about 3.621795.

Added by:Adrian Kuegel
Date:2007-07-06
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:own problem, used in University of Ulm Local Contest 2007

hide comments
2019-12-19 01:17:08 Sigma Kappa
Doesn't one simply calculate values at at most three different points? I am using PI = 2*acos(0.00). Lots of WA. Any corner cases?
2017-01-11 21:39:38
Idk why I had to face the compilation error, accepted second time with the same code :-/
2015-08-02 19:04:28 shantanu tripathi
accepted in one go.. :)
2015-08-02 19:02:20 alok singh
silly mistake caused me one wrong ans.... :P
2015-07-26 21:10:40 shubham
for second case.....optimal radius should be 6.03..isn't it?
2014-11-15 17:17:20 Shubham Mohanka
are there any corner cases.my output for the test cases is exact and i have use pi=3.141592653589.Still getting WA


Last edit: 2014-11-15 17:52:28
2013-04-29 12:04:19 ওয়াসী (Wasi)
My 50th Solved Classical...
2013-02-19 14:39:19 lucky singh
use double instead of float
2012-12-31 18:46:04 Akb
plz take a very accurate value of pi(i took 3.141592653589) to avoid senseless WAs...
2012-12-10 20:46:35 Anuj_LuckFove!
woa didnt expect an AC on the first attempt...nice problem though.. :)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.