painting-the-logo

Rahul has set upon the quest for a new logo of his company. He has created the following continuous logo:  

    /\
   /  \
  / /\ \
 / /  \ \
/ / /\ \ \
  \ \ \/ / /
   \ \  / /
    \ \/ /
     \  /
      \/

However, his sister, Rashi, likes the following discontinuous design more  

   /\
  /  \
 / /\ \
/ /  \ \
  \ \  / /
   \ \/ /
    \  /
     \/

The size of a logo is the longest continuous streak of same characters on an arm.

So, size of 1st logo is 5 while that of 2nd one is 4.

We know that every '/' or '\' character requires exactly 1 unit of paint.

Now, Rahul has X units of paint and would like to draw each of the two favorite logos of himself and his sister, Rashi. So, as to consume it optimally, he wants to know the maximal possible sizes of the two logos that can be drawn such that the difference in sizes of both logos is atmost 1.

Note that it is necessary to be able to draw both the logos. In case, the paint is not enough, output 0 0 instead.

Input Format:

The first line of input file contains T, the number of test cases to follow.
Each test case contains exactly 1 line containing X, the amount of paint Rahul has.

Output Format:

Print two space-separated integers, which denote sizes of Rahul's favourite logo and Rashi's favorite logo, respectively. 

Constraints:

1 ≤ T ≤ 10^5 
1 ≤ N ≤ 10^15

Sample Explanation:

Case #1: We have only 10 units of paint which is not enough to draw both logos.
Case #2: We have 20 units of paint and following logos can, hence, be drawn.

/\
  \/
 /\
/  \
    /
   \/ 

This requires exactly 12 units, and we cannot do better

SAMPLE INPUT
3
10
20
30

SAMPLE OUTPUT
0 0
1 2
3 2

Difficulty: MEDIUM
Tags: Sorting
Skill types: Sorting

Starter code:

Solutions:
import math
t=eval(input())
#2n*(2n+2)+4n*n or 4n^2+8n+4
for i in range(t):
	n=eval(input())
	if n<12:
		print(0, end=' ')
		print(0)
		continue
	x=int((-4+math.sqrt(16+32*n))/16.0)
	xplus=int((-12+math.sqrt(16+32*n))/16.0)
	if 8*pow(x,2)+4*x>8*pow(xplus,2)+12*xplus+4:
		print(2*x-1, end=' ')
		print(2*x)
	else:
		print(2*xplus+1, end=' ')
		print(2*xplus)
'''8x^2+4x-n=0
x=(-4+sqrt(16+32n))/16.0
8x^2+12x-n+4=0
x=(-12+sqrt(16+32n))/16.0'''



####  \ \ \/ / /
####   \ \  / /
####    \ \/ /
####     \  /
####      \/
#####n odd
###n=7
##n=int(input())
##def fore(n):
##    for i in range(n):
##        if i % 2 == 0:
##            strx = ((n-1-i)*" " + "/ "*(i//2) + "/\\" + (i//2) * " \\")
##            print(strx)
##        else:
##            print(" " * (n-1-i) + (i//2+1)*'/ ' + (i//2+1) * ' \\')
##def bg(n):
##    for i in range(n-1, -1, -1):
##        if i % 2 == 0:
##            strx = ((n-1-i+1+1)*" " + "\\ "*(i//2) + "\\/" + (i//2) * " /")
##            print(strx)
##        else:
##            print(" " * (n-1+1-i+1) + (i//2+1)*'\\ ' + (i//2+1) * ' /')
##fore(n)
##bg(n)
##fore(n+1)
##bg(n+1)
##

tc = int(eval(input()))
for bad in range(tc):
	i = int(eval(input()))
	if i < 12:
		print("0 0")
	else:
		quadx =int((-6 + (36-8*(4-i))**0.5)/4.0)
		while not (2*quadx**2+6*quadx+4 <= i and (2*(quadx+1)**2+6*(quadx+1)+4 >= i)):
				   quadx += 1
		if quadx % 2 == 1:
			print((str(quadx) + " " + str(quadx+1)))
		else:
			print((str(quadx+1) + " " + str(quadx)))
				   



def paintRequire(num):
	return (4*(num*(num+1)/2))

def otimumPaint(avaPaint,optPaint):
#    print("optimum paint: %s and total paint: %s"%(optPaint,paintRequire(optPaint)))
	if(paintRequire(optPaint) <= avaPaint):
		return True
	else:
		return False

tc = int(input())

while tc >0:
	x = int(input())
	low = 0
	high = x/4
	ans = -1
	while (low <= high):
		mid = (low + high) >> 1
		if otimumPaint(x,mid):
			low = mid + 1
			ans = mid
		else:
			high = mid -1

	if (ans != (-1)) and (ans != 1):
		if ans%2 == 0:
			print(("%s %s"%(ans-1,ans)))

		else:
			print(("%s %s"%(ans,ans-1)))

	else:
		print("0 0")


	tc-=1