/* Check cf5-opt.vim defs. VIM: let g:lcppflags="-std=c++11 -O2 -pthread" VIM: let g:wcppflags="/O2 /EHsc /DWIN32" VIM: let g:cppflags=g:Iboost.g:Itbb VIM: let g:ldflags=g:Lboost.g:Ltbb.g:tbbmalloc.g:tbbmproxy VIM: let g:ldlibpath=g:Bboost.g:Btbb VIM: let g:argv=" < tic_tac_toy_tomek.sample_input" */ /*! Problem A. Bullseye This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started. Small input 11 points Solve A-small Large input 13 points Solve A-large Problem Maria has been hired by the Ghastly Chemicals Junkies (GCJ) company to help them manufacture bullseyes. A bullseye consists of a number of concentric rings (rings that are centered at the same point), and it usually represents an archery target. GCJ is interested in manufacturing black-and-white bullseyes. Maria starts with t millilitres of black paint, which she will use to draw rings of thickness 1cm (one centimetre). 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 r cm. Then she repeats the following process for as long as she has enough paint to do so: Maria imagines a white ring of thickness 1cm around the last black ring. Then she draws a new black ring of thickness 1cm around that white ring. Note that each "white ring" is simply the space between two black rings. The area of a disk with radius 1cm is ? cm2. One millilitre of paint is required to cover area ? cm2. What is the maximum number of black rings that Maria can draw? Please note that: Maria only draws complete rings. If the remaining paint is not enough to draw a complete black ring, she stops painting immediately. There will always be enough paint to draw at least one black ring. Input The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a line containing two space separated integers: r and t. Output For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the maximum number of black rings that Maria can draw. Limits Small dataset 1 ? T ? 1000. 1 ? r, t ? 1000. Large dataset 1 ? T ? 6000. 1 ? r ? 1018. 1 ? t ? 2 ? 1018. Sample Input 5 1 9 1 10 3 40 1 1000000000000000000 10000000000000000 1000000000000000000 Output Case #1: 1 Case #2: 2 Case #3: 3 Case #4: 707106780 Case #5: 49 */ #include #include #include #include #include #include #include long long solve_puzzle() { long long r; long long t; std::cin >> r; std::cin >> t; long long a = 2; long long b = (2*r-1); long long c = -t; // long double det = double(b)*b-4*a*c; // long double root = (sqrt(det)-b)/(2*a); // long long n = (long long)(floor(root)); long long n = 1; while ( a*n*n+b*n <= t ) n *=2; long long l = 1; long long h = n; while ( h != l+1 ) { long long m = (h+l)/2; if ( a*m*m+b*m <= t) l = m; else h = m; } if ( a*l*l+b*l > t || a*h*h+b*h <= t ) std::cerr << "bug" << std::endl; return l; } int main ( void ) {try{ int puzzle_count; std::cin >> puzzle_count; std::cin.ignore(std::numeric_limits::max(),'\n'); for ( int i = 0; i < puzzle_count; i++ ) { auto s = solve_puzzle(); std::cout << "Case #" << (i+1) << ": " <