The Grand Party
All submissions for this problem are available.
Chef is visiting Netaji Subhash Engineering College in the month of October. The authority planned to set up a welcome programme for Chef. The programme includes a party within the college. To make things look grand, the glasses will be kept in a triangular fashion in such a way that the glasses along the left margin of the triangular structure(including the topmost glass) will be green in color and the rest will be red. You will have to find for N no. of glasses, the number of glasses that will be green. If the triangle cannot be formed with the total number of glasses then print -1.
For example, for N as 6, the bottom row will be of 3 glasses then the 2nd row with 2 glasses and lastly, one at the top. Also, note there can be 1 glass only.
- The first line of the input contains an integer T denoting the number of test cases.
- The first line of each test case contains a single integer N denoting the total number of glasses.
For each test case, output a single line containing the answer.
Input: 2 3 4 Output: 2 -1
Test case 1. A triangular structure can be formed with 3 glasses with each side 2.
Test case 2. A triangular structure cannot be formed with 4 glasses.
|Tags||encoding, horsbug98, horsbug98, maths|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions