Circle Game (Codeforces 1451D)
Tags: Math, geometry

Utkarsh is forced to play yet another one of Ashish's games. The game progresses turn by turn and as usual, Ashish moves first.Consider the 2D plane. There is a token which is initially at $$$(0,0)$$$. In one move a player must increase either the $$$x$$$ coordinate or the $$$y$$$ coordinate of the token by exactly $$$k$$$. In doing so, the player must ensure that the token stays within a (Euclidean) distance $$$d$$$ from $$$(0,0)$$$.In other words, if after a move the coordinates of the token are $$$(p,q)$$$, then $$$p^2 + q^2 \leq d^2$$$ must hold.The game ends when a player is unable to make a move. It can be shown that the game will end in a finite number of moves. If both players play optimally, determine who will win.

Input: The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases.The only line of each test case contains two space separated integers $$$d$$$ ($$$1 \leq d \leq 10^5$$$) and $$$k$$$ ($$$1 \leq k \leq d$$$).

Output: For each test case, if Ashish wins the game, print "Ashish", otherwise print "Utkarsh" (without the quotes).

Note: In the first test case, one possible sequence of moves can be$$$(0, 0) \xrightarrow{\text{Ashish }} (0, 1) \xrightarrow{\text{Utkarsh }} (0, 2)$$$.Ashish has no moves left, so Utkarsh wins.

Sample Inputs:
5
2 1
5 2
10 3
25 4
15441 33

Sample Outputs:
Utkarsh
Ashish
Utkarsh
Utkarsh
Ashish

Solution (Python):
import math
n = int(input())
res = []
for t in range(n):
    (d, k) = map(int, input().split())
    d /= k
    x = d // math.sqrt(2)
    y = x
    x += 1
    if x * x + y * y <= d * d:
        res.append('Ashish')
    else:
        res.append('Utkarsh')
for i in res:
    print(i)

Solution (Python):
for _ in range(int(input())):
    (d, k) = map(int, input().split())
    t = k * 2 ** 0.5
    a = d // t
    x = 2 * a
    p = k * a
    if ((p + k) ** 2 + p ** 2) ** 0.5 <= d:
        x += 1
    if x % 2 == 1:
        print('Ashish')
    else:
        print('Utkarsh')

Solution (Python):
for _ in range(int(input())):
    (d, k) = map(int, input().split())
    r2 = 2 ** (1 / 2)
    diag = int(d / (k * r2)) * k
    maxi = (diag + k) ** 2 + diag ** 2
    print(('Utkarsh', 'Ashish')[maxi <= d ** 2])