Problem:

床

　

  ヒデヨ博士の家の床には正方形のタイルが敷きつめられています。芸術に造詣が深いヒデヨ博士は、赤、黄、青の塗料を使ってタイルに色を塗ることにしました。はじめに部屋の適当なタイルをひとつ選び、以下の方法で色を塗っていきます。

タイルを塗る色を、赤（図の番号１）、黄（図の番号２）、青（図の番号３）の順に変えていき、青の次はまた赤から始める。

すでに色を塗った領域の隣に正方形を追加し、そこに色を塗る。それらを合わせた領域が長方形になるようにする。正方形を追加する方向は、東、北、西、南の順に変えていき、南の次はまた東から始める（図では、上方向が北、右方向が東である）。

  

  最初に赤く塗ったタイルから東西方向に$x$個、南北方向に$y$個移動したところにあるタイルは、何色に塗られているでしょうか。ただし、東の方向を$x$の正の方向、北の方向を$y$の正の方向とします。

  $x$と$y$を入力し、タイルの色を出力するプログラムを作成せよ。

入力

  入力は以下の形式で与えられる。

$x$ $y$

  １行に$x$と$y$ ($-10^6 \leq x,y \leq 10^6$)が与えられる。

出力

  タイルの色が赤のとき1、黄のとき2、青のとき3を１行に出力する。

入出力例

入力例１

0 0

出力例１

1

入力例２

-4 5

出力例２

2

入力例３

8 -14

出力例３

3



Sample input:
0 0


Sample output:
1

Submission status: Accepted

Solution code:
import sys

point=list(map(int,input().split()))
if point[0]==0 and point[1]==0:
    print("1")
    sys.exit()
fiblist=[0,1,1]
maxpoint=[0,0]
minpoint=[0,0]
i=2
while True:
    if i%4==2 or i%4==3:
        maxpoint[i%2]+=fiblist[2]
    else:
        minpoint[i%2]-=fiblist[2]
    if minpoint[0]<=point[0] and maxpoint[0]>=point[0] and minpoint[1]<=point[1] and maxpoint[1]>=point[1]:
        print((i-1)%3+1)
        break
    fiblist[0]=fiblist[1]
    fiblist[1]=fiblist[2]
    fiblist[2]=fiblist[0]+fiblist[1]
    i+=1

Submission status: Accepted

Solution code:
x, y = map(int, input().split())

max_i = 0
max_j = 0
min_i = 0
min_j = 0
color = [1, 2, 3]
i = 0
while True :
    if min_i <= x <= max_i and min_j <= y <= max_j :
        ans = color[i]
        break
    i += 1
    if i >= 3 :
        i = 0
    l = max_j+1  - min_j
    max_i += l
    
    if min_i <= x <= max_i and min_j <= y <= max_j :
        ans = color[i]
        break
    i += 1
    if i >= 3 :
        i = 0
    l = max_i+1  - min_i
    max_j += l
    
    if min_i <= x <= max_i and min_j <= y <= max_j :
        ans = color[i]
        break
    i += 1
    if i >= 3 :
        i = 0
    l = max_j+1  - min_j
    min_i -= l
    
    if min_i <= x <= max_i and min_j <= y <= max_j :
        ans = color[i]
        break
    i += 1
    if i >= 3 :
        i = 0
    l = max_i+1  - min_i
    min_j -= l

print(ans)

Submission status: Accepted

Solution code:
import copy
x,y = map(int,input().split())
color = 1
za = [0,0]
n = 0
m = 1
l = 1
d = 1
X = 0
Y = 0
while True:
    if za[0] <= x and za[0]+l-1 >= x and za[1] >= y and za[1]-l+1 <= y:
        print(color)
        break
    m = copy.deepcopy(l)
    l += n
    n = m
    color += 1
    if color > 3:
        color = 1
    if d == 1:
        za[0] += n
        za[1] = Y
        d = 2
    #print(za)
    elif d == 2:
        za[0] = X
        za[1] += l
        Y = za[1]
        d = 3
    elif d == 3:
        za[0] -= l
        za[1] = Y
        X = za[0]
        d = 4
    elif d == 4:
        za[0] = X
        za[1] -= n
        d = 1
    #print(za,X,Y,l,color)

Submission status: Accepted

Solution code:
x,y = (int(_) for _ in input().split())
minX = minY = dir = 0
maxX = maxY = 1

while 1:
    if minX <= x and x < maxX and minY <= y and y < maxY:
        break
    if dir % 4 == 0:
	    maxX += max(maxX - minX,maxY - minY)
    elif dir % 4 == 1:
        maxY += max(maxX - minX, maxY - minY)
    elif dir % 4 == 2:
        minX -= max(maxX - minX, maxY - minY)
    else:
        minY -= max(maxX - minX, maxY - minY)
    dir += 1
print((dir % 3) + 1)

Submission status: Accepted

Solution code:
import sys
x,y = list(map(int, input().split()))

cnt = 1
xy = [0,0]
xy2 = [1,1]
if xy[0] <= x < xy2[0] and xy[1] <= y < xy2[1]:
    print(cnt)
    sys.exit(0)
while 1:
    if cnt % 4 == 1:
        xy2[0] += xy2[1] - xy[1]
    elif cnt % 4 == 2:
        xy2[1] += xy2[0] - xy[0] 
    elif cnt % 4 == 3:
        xy[0] -= xy2[1] - xy[1]
    elif cnt % 4 == 0:
        xy[1] -= xy2[0] - xy[0]
    if xy[0] <= x < xy2[0] and xy[1] <= y < xy2[1]:
        print((cnt % 3) + 1)
        break
    cnt += 1

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

x,y = [int(i) for i in input().split()]

fiboMax = 100

fibo = [0 for i in range(fiboMax)]
fibo[1] = 1
fibo[2] = 1

for i in range(3,fiboMax):
    fibo[i] = fibo[i-1] + fibo[i-2]
    
xMax = 0
yMax = 0
xMin = 0
yMin = 0

ans = -1
if(x <= xMax and y <= yMax and x >= xMin and y >= yMin):
    ans = 1
else:
    i = 2
    while(True):
        xMax += fibo[i]
        if(x <= xMax and y <= yMax and x >= xMin and y >= yMin):
            ans = i
            break
        else:
            i += 1
        yMax += fibo[i]
        if(x <= xMax and y <= yMax and x >= xMin and y >= yMin):
            ans = i
            break
        else:
            i += 1
        xMin -= fibo[i]
        if(x <= xMax and y <= yMax and x >= xMin and y >= yMin):
            ans = i
            break
        else:
            i += 1
        yMin -= fibo[i]
        if(x <= xMax and y <= yMax and x >= xMin and y >= yMin):
            ans = i
            break
        else:
            i += 1

ans %= 3
if ans == 0:
    ans = 3

print(ans)

Submission status: Accepted

Solution code:
def search(x, y):
    x_min = 0
    y_min = 0
    x_max = 0
    y_max = 0
    f = 0
    f1 = 1
    f2 = 0
    p = 0
    while(True):
        if ( x_min <= x and x <= x_max and
             y_min <= y and y <= y_max  ): return p%3 + 1
        f = f1 + f2
        if ( p % 4 == 0 ):  x_max += f  # east
        elif ( p % 4 == 1 ): y_max += f # north
        elif ( p % 4 == 2 ): x_min -= f # west
        else:  y_min -= f               # south
        f2 = f1
        f1 = f
        p = p + 1

x,y = map(int, input().split())
print(search(x, y))

Submission status: Accepted

Solution code:
fib = [0, 1, 1]
for i in range(35):
    fib.append(fib[-1]+fib[-2])
x, y = map(int, input().split())
xn, xm, yn, ym = 0, 0, 0, 0
i = 2
color = 1
if (xn <= x <= xm) and (yn <= y <= ym):
    print(1)
    exit()
while True:
    if i % 4 == 2:
        xn += fib[i-1]
        xm += fib[i]
        yn += 0
        ym += fib[i-2]
    elif i % 4 == 3:
        xn -= fib[i-2]
        xm += 0
        yn += fib[i-1]
        ym += fib[i]
    elif i % 4 == 0:
        xn -= fib[i]
        xm -= fib[i-1]
        yn -= fib[i-2]
        ym += 0
    else:
        xn += 0
        xm += fib[i-2]
        yn -= fib[i]
        ym -= fib[i-1]
    color %= 3
    color += 1
    # print(xn, xm, yn, ym, i-2, color)
    if (xn <= x <= xm) and (yn <= y <= ym):
        print(color)
        break
    i += 1

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
tx, ty = 0, 0
a = 1
b = 1
ans = 1
while 1:
    if (tx,ty) == (x,y): break

    b += a
    tx += b-1
    ans += 1
    #print(tx-a+1, tx, "  ", ty, ty+a-1)
    if tx-a+1<=x<=tx and ty<=y<=ty+a-1: break

    a += b
    ty += a-1
    ans += 1
    #print(tx-b+1, tx, "  ", ty-b+1, ty)
    if tx-b+1<=x<=tx and ty-b+1<=y<=ty: break

    b += a
    tx -= b-1
    ans += 1
    #print(tx, tx+a-1, "  ", ty+a+1, ty)
    if tx<=x<=tx+a-1 and ty-a+1<=y<=ty: break

    a += b
    ty -= a-1
    ans += 1
    #print(tx, tx+b-1, "  ", ty, ty+b-1)
    if tx<=x<=tx+b-1 and ty<=y<=ty+b-1: break
print(ans%3 if ans%3 else 3)

Submission status: Accepted

Solution code:
# AOJ 0409
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0409

xx, yy = list(map(int, input().split()))

fib = [1, 1]
a = 0
while a < 10000000:
    a = fib[-1] + fib[-2]
    fib += [a]

area = [[0, 0, 1]]
x, y = 0, 0
f1 = 0
f2 = 1
for n in range(1, len(fib)):
    a = fib[n]
    if n % 4 == 1:
        area += [[x + f2, y + f1, a]]
    elif n % 4 == 2:
        area += [[x - f1, y + a, a]]
    elif n % 4 == 3:
        area += [[x - a, y, a]]
    elif n % 4 == 0:
        area += [[x, y - f2, a]]
    f1 = f2
    f2 = a
    x, y = area[-1][0:2]

for n, floor in enumerate(area):
    x, y, a = floor
    if x <= xx < x + a and y - a < yy <= y:
        print(n % 3 + 1)
        break

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
left,right,up,down = 0,0,0,0
fiv1 = 0
fiv2 = 1
color = [1,2,3]
ans = 0
while not(left <= x <= right) or not(down <= y <=up):
  num = fiv1 + fiv2
  right += num
  fiv1 = fiv2
  fiv2 = num
  ans += 1
  
  if left <= x <= right and down <= y <= up:
    break
  num = fiv1 + fiv2
  up += num
  fiv1 = fiv2
  fiv2 = num
  ans += 1 

  if left <= x <= right and down <= y <= up:
    break
  num = fiv1 + fiv2
  left -= num
  fiv1 = fiv2
  fiv2 = num
  ans += 1

  if left <= x <= right and down <= y <= up:
    break  
  num = fiv1 + fiv2
  down -= num
  fiv1 = fiv2
  fiv2 = num
  ans += 1
print(color[ans%3])