URI Online Judge | 1935


By Guilherme Albuquerque Pinto BR Brazil

Timelimit: 1

Given a board dimensions N × N, would like to place beans, a grain in each square, following a spiral as shown in the figure. Starting from the top left corner, with coordinates (1, 1), and then going right as possible, then down as possible, then to the left as possible and then up as possible. We repeat this pattern, right-down-left-up, until B beans are placed on the board. The problem is: given N and B data, in which coordinates will be placed the last grain of beans? In the figure, for N = 8 and B = 53, the last grain was placed on the squared coordinates (4, 6).


The entry contains only one line with two integers, N and B, where 1 ≤ N ≤ 230 and 1 ≤ BN2.


Your program should produce a single line with two integers L and C representing the coordinates of the last grain of beans.

Input Samples Output Samples

8 53

4 6

1073741824 1152921504603393520

536871276 536869983