BOJ - 4395 - Steps

Updated:

import sys
import math

def fact(n):
    a = 1
    for i in range(1, n+1):
        a = a * i
    return a

def solution():
    N = int(sys.stdin.readline())  
    
    for _ in range(N):
        X, Y = map(int, input().split(' '))
    
        distance = Y - X
        i = 1
        while i * i < distance:
            i = i + 1
    
        if distance < (i * i) - i + 1:
            print(2 * i - 2)
        else:
            print(2 * i - 1)

solution()

https://www.acmicpc.net/problem/4395

Categories:

Updated:

Leave a comment