Under construction

Still being built. Things may change

Spiral

Interview

Time limit1sMemory limit512 MB

Summary
Place B beans in a clockwise inward spiral on an N by N board and report the row and column of the B-th bean.
Level

Medium6 of 10

Topics
Math, Implementation, Binary search, Simulation
Solved
No attempts yet

Problem

You place beans on an N×NN \times N board, one bean per square, in the spiral order shown in the figure.

Start at the top left square (1,1)(1, 1) and move right. When the next square is off the board or already holds a bean, turn down. The same rule turns down into left, left into up, and up back into right, so the direction cycles right, down, left, up until all BB beans are placed.

Given NN and BB, find the coordinates of the square that holds the last bean. A coordinate (L,C)(L, C) means row LL counted from the top and column CC counted from the left. The figure shows N=8N = 8 and B=53B = 53, where the last bean lands on (4,6)(4, 6).

Input

One line with two integers NN and BB separated by a space, where 1≤N≤2301 \le N \le 2^{30} and 1≤B≤N21 \le B \le N^2.

Output

Print the row number LL and the column number CC of the last bean on one line, separated by a space.

Examples2

  1. Example 1

    Input
    8 53
    
    Expected output
    4 6
    
  2. Example 2

    Input
    1073741824 1152921504603393520
    
    Expected output
    536871276 536869983