Spiral

Given a N × N grid, we would like to place beans, one in each square, following a spiral as shown in the picture. Starting from the upper-left square, with coordinates (1, 1), and then going to the right until possible, then down until possible, then left until possible and then up until possible. We repeat this pattern, right- downleft-up, until B beans are placed into the grid. The problem is: given N and B, at which coordinates will the last bean be placed? In the picture, for N = 8 and B = 53, the last bean is placed at coordinates (4, 6). Input The input contains several test cases. A test case consists of a single line containing two integers, N and B, where 2 ≤ N ≤ 230 and 1 ≤ B ≤ N2. Output For each test case in the input your program must output one line containing two integers, R and C, where (R,C) are the coordinates of the last bean. Sample Input 8 53 1073741824 1152921504603393520 Sample Output 46 536871276 536869983