Bullseye
InterviewTime limit5sMemory limit512 MB
Starting from a white circle of radius r, count how many alternating 1cm black rings the paint budget can complete.
- Level
Medium5 of 10
- Topics
- Binary search, Math
- Solved
- No attempts yet
Problem
Maria works for a company that manufactures black-and-white bullseyes. A bullseye is a stack of rings formed between concentric circles, circles that share one center, and it usually represents an archery target.

Maria has millilitres of black paint, and she draws rings of thickness 1cm with it. A ring of thickness 1cm is the space between two concentric circles whose radii differ by 1cm.
Maria draws the first black ring around a white circle of radius cm. After that she repeats the following process for as long as she has enough paint.
- Maria imagines a white ring of thickness 1cm around the last black ring.
- She draws a new black ring of thickness 1cm around that white ring.
Each white ring is only the empty space left between two black rings.
A disk of radius 1cm has area cm. One millilitre of paint covers area cm. Find the maximum number of black rings Maria can draw. Note these two conditions.
- Maria draws complete rings only. If the paint left is not enough for one whole black ring, she stops immediately.
- The paint is always enough for at least one black ring.
Input
The first line contains the number of test cases . Each of the next lines contains two integers and separated by one space.
Constraints
- , so at least one black ring always fits.
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is the maximum number of black rings Maria can draw.