Problem:


Score : 600 points

Problem Statement

Ringo Mart, a convenience store, sells apple juice.

On the opening day of Ringo Mart, there were A cans of juice in stock in the morning.
Snuke buys B cans of juice here every day in the daytime.
Then, the manager checks the number of cans of juice remaining in stock every night.
If there are C or less cans, D new cans will be added to the stock by the next morning.

Determine if Snuke can buy juice indefinitely, that is, there is always B or more cans of juice in stock when he attempts to buy them.
Nobody besides Snuke buy juice at this store.

Note that each test case in this problem consists of T queries.

Constraints

1 \leq T \leq 300

1 \leq A, B, C, D \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

T
A_1 B_1 C_1 D_1
A_2 B_2 C_2 D_2
:
A_T B_T C_T D_T

In the i-th query, A = A_i, B = B_i, C = C_i, D = D_i.

Output

Print T lines. The i-th line should contain Yes if Snuke can buy apple juice indefinitely in the i-th query; No otherwise.

Sample Input 1

14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985

Sample Output 1

No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

In the first query, the number of cans of juice in stock changes as follows: (D represents daytime and N represents night.)

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 6
→D x

In the second query, the number of cans of juice in stock changes as follows:

9
→D 2
→N 11
→D 4
→N 13
→D 6
→N 15
→D 8
→N 8
→D 1
→N 10
→D 3
→N 12
→D 5
→N 14
→D 7
→N 7
→D 0
→N 9
→D 2
→N 11
→D …

and so on, thus Snuke can buy juice indefinitely.

Sample Input 2

24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1

Sample Output 2

No
No
No
No
No
No
Yes
Yes
No
No
No
No
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
No
No
No



Sample input:
14
9 7 5 9
9 7 6 9
14 10 7 12
14 10 8 12
14 10 9 12
14 10 7 11
14 10 8 11
14 10 9 11
9 10 5 10
10 10 5 10
11 10 5 10
16 10 5 10
1000000000000000000 17 14 999999999999999985
1000000000000000000 17 15 999999999999999985


Sample output:
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
No
No
Yes

Submission status: Accepted

Solution code:
from fractions import gcd

T, *L = map(int, open(0).read().split())

for a, b, c, d in zip(*[iter(L)] * 4):
    if a < b or d < b:
        flag = False
    elif c >= b - 1:
        flag =  True
    else:
        g = gcd(b, d)
        flag = (b + a % g - g) <= c

    if flag:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from fractions import gcd

def solve(a, b, c, d):
    if a < b or d < b:
        return False

    if c >= b - 1:
        return True

    g = gcd(b, d)
    return (b + a % g - g) <= c

T, *L = map(int, open(0).read().split())

for t in zip(*[iter(L)] * 4):
    if solve(*t):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


t = I()
for i in range(t):
    a, b, c, d = LI()
    g = gcd(b, d)
    if b > d or a < b:
        print('No')
    elif c >= b - 1:
        print('Yes')
    elif (a - (b - 1) - 1) // g != (a - (c + 1)) // g:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
T = int(input())

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

ans = []
for _ in range(T):
    A, B, C, D = map(int, input().split())

    if A < B:
        ans.append('No')
        continue

    if B > D:
        ans.append('No')
        continue

    if C >= B:
        ans.append('Yes')
        continue

    # A >= B, B <= D, C < B
    G = gcd(D, B)
    maxMod = B - G + A % G
    if C < maxMod:
        ans.append('No')
    else:
        ans.append('Yes')

print(*ans, sep='\n')

Submission status: Accepted

Solution code:
from fractions import gcd
n = int(raw_input())
lim = 10**19
for i in xrange(n):
	a, b, c, d = map(int, raw_input().split())
	if a < b or d < b:
		print 'No'
	else:
		# c - b + 1
		e = c - b + 1
		g = gcd(b, d)
		dist = abs(a % g) - abs(e % g) + g
		dist %= g
		e += dist
		if e < 0 or e > c - b + d:
			print 'No'
		else:
			print 'Yes'

Submission status: Accepted

Solution code:
import os
import sys
from fractions import gcd

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

T = int(sys.stdin.readline())
ABCD = [list(map(int, sys.stdin.readline().split())) for _ in range(T)]


def solve(A, B, C, D):
    if B > D:
        return False
    if A < B:
        return False
    if C >= B:
        return True
    # C < B <= D
    # A から D を無限に足してったとき、mod B が C より大きくなったらだめ
    p = gcd(D, B)  # p ごとの値しか取らない
    if p < B - C:
        return False
    if (B - A - 1) % p < B - C - 1:
        return False
    return True


ans = []
for a, b, c, d in ABCD:
    ans.append('Yes' if solve(a, b, c, d) else 'No')
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

T = int(sys.stdin.readline())
ABCD = [list(map(int, sys.stdin.readline().split())) for _ in range(T)]


def solve(A, B, C, D):
    if B > D:
        return False
    if A < B:
        return False
    if C >= B:
        return True
    # C < B <= D
    # A から D を無限に足してったとき、mod B が C より大きくなったらだめ
    p = gcd(D, B)  # p ごとの値しか取らない
    if p < B - C:
        return False
    if (B - A - 1) % p < B - C - 1:
        return False
    return True


ans = []
for a, b, c, d in ABCD:
    ans.append('Yes' if solve(a, b, c, d) else 'No')
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

from fractions import gcd

T = int(input())
ABCD = [[int(x) for x in input().split()] for _ in range(T)]

def F(A,B,C,D):
    if D<B:
        return False
    if A<B:
        return False
    g = gcd(D,B)
    # 個数 mod gは不変量。平行移動して、g=1に帰着する。
    diff = A%g
    A -= diff
    C -= diff
    C -= C%g
    A //= g; B //= g; C //= g; D //= g
    # 以下、(B,D) = 1. mod Dで任意の状態になる
    # C+1,...,C+Bの全部をとる。
    # C+1 >= Bが必要十分
    return C+1>=B

print('\n'.join('Yes' if F(a,b,c,d) else 'No' for a,b,c,d in ABCD))

Submission status: Accepted

Solution code:
#!py2
from fractions import gcd

def solve(initial, burn, check, resupply):
    if burn > initial or burn > resupply:
        return False
    if check >= burn:
        return True

    x = initial % burn
    g = gcd(resupply, burn)
    
    # k largest with x + k*g < burn, then decide if x + k*g <= check
    k = (burn - x) // g
    if k * g + x == burn: k -= 1
    return x + k * g <= check

for _ in xrange(int(raw_input())):
    print "Yes" if solve(*map(int, raw_input().split())) else "No"

Submission status: Accepted

Solution code:
from fractions import gcd
t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if a < b or d < b:
        print("No")
        continue
    if c >= b-1:
        print("Yes")
        continue
    g = gcd(b, d)
    print("Yes" if b + a%g - g <= c else "No")

Submission status: Accepted

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)

n=int(input())
for _ in range(n):
  a,b,c,d=map(int,input().split())
  if a<b or a%b>c or b>d:
    print('No')
  else:
    if b==d:
      print('Yes')
    elif a%b+d==a:
      print('Yes')
    else:
      if c+gcd(b,d)>=b:
        print('Yes')
      else:
        print('No')

Submission status: Accepted

Solution code:
import fractions

T = int(input())
for i in range(T):
    A, B, C, D = map(int, input().split())
    if A < B:
        print('No')
        continue
    if B > D:
        print('No')
        continue
    if C >= B - 1:
        print('Yes')
        continue
    A = A % B
    D = D % B
    BD = fractions.gcd(B, D)
    A_max = A + BD * ((B - 1 - A) // BD)
    if A_max > C:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == 0:
        return a
    return gcd(b, a % b)

def check(A, B, C, D):
    if A < B:
        return False
    if C < A % B:
        return False
    if D < B:
        return False
    x = gcd(B, D)
    return B <= C + x

def main():
    T = int(input())
    for _ in range(T):
        A, B, C, D = map(int, input().split())
        if check(A, B, C, D):
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
T = int(input())


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


for i in range(T):
    a, b, c, d = map(int, input().split())
    if a < b:
        print('No')
    elif d < b:
        print('No')
    elif c >= b:
        print('Yes')
    else:
        g = gcd(b, d)
        if b - g + a % g > c:
            print('No')
        else:
            print('Yes')

Submission status: Accepted

Solution code:
gcd = lambda x,y: x if y==0 else gcd(y,x%y)

t = int(input())
for i in range(t):
    a,b,c,d = map(int,input().split())
    dx = d%b
    if a<b:
        print('No')
    elif d<b:
        print('No')
    elif c>=b:
        print('Yes')
    elif a%b>c:
        print('No')
    elif dx==0:
        print('Yes')
    else:
        if b - gcd(b,d) + a%gcd(b,d) > c:
            print('No')
        else:
            print('Yes')

Submission status: Accepted

Solution code:
import fractions as f
for i in range(int(input())):
 a,b,c,d=map(int,input().split())
 g=f.gcd(b,d)
 print("No" if a<b or b>d or a-((a-b)//g+1)*g>c else "Yes")

Submission status: Accepted

Solution code:
import fractions as f
for i in range(int(input())):
 a,b,c,d=list(map(int,input().split()))
 g=f.gcd(b,d)
 if a<b or b>d or a-((a-b)//g+1)*g>c:
  print("No")
 else:
  print("Yes")

Submission status: Accepted

Solution code:
T = int(input())
ABCD = [list(map(int, input().split())) for _ in range(T)]

from fractions import gcd

for a,b,c,d in ABCD:
  if a<b:
    print('No')
    continue
    
  l = gcd(b,d)
  a = a % b
  if (a + ((b-a-1)//l)*l) <= c and (a - (a//l)*l)+d>=b:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
from fractions import gcd

t = int(input())
for _ in range(t):
    a, b, c, d = list(map(int, input().split()))
    if b > a:
        print("No")
    elif b > d:
        print("No")
    elif c >= b:
        print("Yes")
    else:
        g = gcd(b, d)
        if b - g + (a % g) > c:
            print("No")
        else:
            print("Yes")

Submission status: Accepted

Solution code:
t=int(input())
def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)
for i in range(t):
  a,b,c,d=map(int,input().split())
  if a<b:
    print("No")
  elif b>d:
    print("No")
  elif c>b:
    print("Yes")
  else:
    if b-gcd(b,d)+a%gcd(b,d)>c:
      print("No")
    else:
      print("Yes")

Submission status: Accepted

Solution code:
t = int(input())
query = [tuple(map(int, input().split())) for _ in range(t)]
def gcd(x, y):
    if y == 0: return x
    return gcd(y, x % y)
for a, b, c, d in query:
    g = gcd(b, d)
    r = a % g
    m = ((c - r)//g + 1) * g
    if b <= m and b <= a and b <= d: print('Yes')
    else: print('No')

Submission status: Accepted

Solution code:
T = int(input())

def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
def lcm (a: int,b: int) -> int:
    return a // gcd(a,b) * b


for i in range(T):
    A,B,C,D = map(int,input().split(" "))
    g = gcd(B,D)
    if A < B or D < B:
        print("No")
        continue
    if C >= ((B - g) + (A % g)):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def gcd(a, b):
    if b>a:
        a, b = b, a
    while b>0:
        a, b = b, a%b
    return a

def solve(T: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):
    for i in range(T):
        a, b, c, d = A[i], B[i], C[i], D[i]
        if a<b or b>d:
            print('No')
            continue
        x = (c-a+1)%b
        g = gcd(b, d)
        print('No' if -(-x//g*g) - x + c+1 < b else 'Yes')


    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    T = int(next(tokens))  # type: int
    A = [int()] * (T)  # type: "List[int]" 
    B = [int()] * (T)  # type: "List[int]" 
    C = [int()] * (T)  # type: "List[int]" 
    D = [int()] * (T)  # type: "List[int]" 
    for i in range(T):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(T, A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from fractions import gcd
def f(a,b,c,d):
    if a<b:
        return 0
    if b>d:
        return 0
    if b<=c:
        return 1
    x=a%b
    g=gcd(b,d)
    if c>=b-g+(x%g):
        return 1
    else:
        return 0
T=int(input())
X=[[int(i) for i in input().split()] for i in range(T)]
for a,b,c,d in X:
    s=f(a,b,c,d)
    if s:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from fractions import gcd
def f(a,b,c,d):
    if a<b:
        return 0
    if b>d:
        return 0
    if b-1<=c:
        return 1
    x=a%b
    #print(3)
    if b==d:
        if c<x:
            return 0
        elif c>=x:
            return 1
    #print(4)
    if c<x:
        return 0
    e=(d-b)%b
    d1=gcd(e,b)
    q=(c+1-x)//d1
    q1=(b-1-x)//d1
    #print(d1,q,q1,x,(c+1-x)%d1)
    if q<q1:
        return 0
    if (c+1-x)%d1==0:
        return 0
    return 1
T=int(input())
X=[[int(i) for i in input().split()] for i in range(T)]
for a,b,c,d in X:
    s=f(a,b,c,d)
    if s:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())

    if B > A:
        print('No')
    elif B > D:
        print('No')
    elif C >= B:
        print('Yes')
    elif A % B > C:
        print('No')
    else:
        s = A % B
        g = gcd(B, D)
        if s + (B-1-s)//g*g > C:
            print('No')
        else:
            print('Yes')

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())

    if B > A:
        print('No')
    elif B > D:
        print('No')
    elif C >= B:
        print('Yes')
    else:
        g = gcd(B, D)
        if B - g + (A % g) > C:
            print('No')
        else:
            print('Yes')

Submission status: Accepted

Solution code:
def Yes():
  print("Yes")
def No():
  print("No")

def gcd(x, y):
  b = max(x, y)
  s = min(x, y)
  r = b % s
  while r != 0:
    b = s
    s = r
    r = b % s
  return s

def lcm(x, y):
  return (x * y) // gcd(x,y)

def main():
  T = int(input())
  AD = [list(map(int, input().split())) for i in range(T)]

  for i in AD:
    A = i[0]
    B = i[1]
    C = i[2]
    D = i[3]
    if A < B:
      No()
      continue
    if B > D:
      No()
      continue
    add = D - B
    d = gcd(B, D)
    
    C += 1
    t = C % d
    k = A % d
    if k == t:
      LD = C
    elif k > t:
      LD = C + k - t
    else:
      LD = C + d - t + k
    if LD < B:
      No()
    else:
      Yes()

main()

Submission status: Accepted

Solution code:
def g(a, b):
    if a%b == 0: return b
    return g(b, a%b)

def f(a, b, c, d):
    yes = "Yes"
    no  = "No"
    if a<b or d<b: return no
    if c>=b or a<=c: return yes
    if (a-c)%b>0 and (a-c)%b<b-c: return no
    e = d%b
    if e==0 or b-c==1: return yes
    if e==1: return no
    h = g(b, e)
    if h<b-c: return no
    if (a-c)%h>0 and (a-c)%h<b-c: return no
    return yes

t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    ans = f(a, b, c, d)
    print(ans)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0:return a
    return gcd(b, a % b)

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    #exception
    if a < b or d < b:
        print("No")
        continue

    if c >= b:
        print("Yes")
        continue

    g = gcd(d, b)
    print("Yes" if b - g + a % g <= c else "No")

Submission status: Accepted

Solution code:
T = int(input())
ABCD = [[int(_) for _ in input().split()] for _ in range(T)]


def gcd(x, y):
    if x < y:
        return gcd(y, x)
    elif x % y == 0:
        return y
    else:
        return gcd(y, x % y)


for a, b, c, d in ABCD:
    if a < b or d < b:
        print('No')
    else:
        g = gcd(b, d)
        x = g * (c // g) + (a % g)
        if x <= c:
            x += g
        if x >= b:
            print('Yes')
        else:
            print('No')

# https://www.youtube.com/watch?v=eB0eT-948Vw

Submission status: Accepted

Solution code:
from fractions import gcd
T=int(input())
for i in range(T):
  A,B,C,D=map(int,input().split())
  if B<=A and B<=D:
    if B<=C:
      print("Yes")
    else:
      G=gcd(B,D)
      a=A%G
      t=(C-a)//G+1
      if B>t*G+a:
        print("No")
      else:
        print("Yes")
  else:
    print("No")

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
def inpl(): return [int(i) for i in input().split()]
T = int(input())
for _ in range(T):
    A, B, C, D = inpl()
    if A < B or B > D:
        print('No')
        continue
    if C >= B:
        print('Yes')
        continue
    gcdbd = gcd(B, D)
    if (1+(C-A%B)//gcdbd)*gcdbd+A%B >= B:
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
import fractions
n = int(input())
for i in range(n):
  a,b,c,d = map(int,input().split())
  if b > d or b > a:print("No")
  elif b <= c:print("Yes")
  else:
    num = fractions.gcd(b,d)
    if b-num+(a%num) > c:print("No")
    else:print("Yes")

Submission status: Accepted

Solution code:
import sys

iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]

def fGcd(iX,iY):
    while iY:
        iX,iY= iY,iX%iY
    return iX

def fFunc(iA,iB,iC,iD):
    ig = fGcd(iB,iD)
    if iA < iB or iD < iB:
        return False
    elif iC >= iB :
        return True
#こういうことか。やっぱりわかってないなぁ。つらい
#   elif iC < iA % iB :
#       return False
#   elif iB <= ig + iC :

# AtCoder の解法
    elif iB <= iC +ig - iA % ig  :
        return True
    else:
        return False

for eR in aR:
    if fFunc(*eR) :
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from fractions import gcd
n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]
for i in range(n):
    a,b,c,d = A[i]
    g = gcd(b,d)
    if a < b or b > d or b-g+(a%g)>c:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys

iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]

def fGcd(iX,iY):
    while iY:
        iX,iY= iY,iX%iY
    return iX

def fFunc(iA,iB,iC,iD):
    ig = fGcd(iB,iD)
    if iA < iB or iD < iB:
        return False
    elif iC >= iB :
        return True
    elif iC < iA % iB :
        return False

# これでも通る
    elif iB <= ig + iC :
# AtCoder の解法
#   elif iB <= iC +ig - iA % ig  :
        return True
    else:
        return False

for eR in aR:
    if fFunc(*eR) :
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
import sys

iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]

def fGcd(iX,iY):
    while iY:
        iX,iY= iY,iX%iY
    return iX

#これものすごくわりきってるけど通るのか？

def fFunc(iA,iB,iC,iD):
    if iA < iB or iD < iB:
        return False
    elif iC >= iB :
        return True
    elif iC < iA % iB :
        return False
    elif iB -iC - 1 < fGcd(iB,iD) :
        return True
    else:
        return False

for eR in aR:
    if fFunc(*eR) :
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

from math import ceil
from fractions import gcd

def solve(A, B, C, D):
    if A < B or D < B: return False
    if A % B > C: return False
    if D % B == 0: return True

    g = gcd(B, D)
    r = A % g  # +D -B を繰り返すと x % g == r であるxを訪れる
    # x % g == r and C < x < B である x が存在するなら False を返す
    return not (C < B - g + r)

T = int(input())
for i in range(T):
    A, B, C, D = [int(t) for t in input().split()]
    print('Yes' if solve(A, B, C, D) else 'No')

Submission status: Accepted

Solution code:
n = int(input())
def gcd(x,y):
	if x%y: return gcd(y,x%y)
	else: return y
for _ in range(n):
	a,b,c,d = (int(i) for i in input().split())
	g = gcd(b,d)
	if a<b or b>d or b-g+(a%g)>c: print("No")
	else: print("Yes")

Submission status: Accepted

Solution code:
T  = int(input())
def gcd(a,b):
    if b==0: return a
    return gcd(b, a%b)
for _ in range(T):
    a,b,c,d =list( map(int, input().split()) )
    if a<b or d<b:
        print('No')
        continue
    a %= b
    d%=b
    d = gcd(d,b)
    if c>= b:
        print('Yes')
        continue
    x = (b-a)//d
    y = a+ x*d
    if y == b: y-=d
    if y>c:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
t = int(input())
abcd = [tuple(int(x) for x in input().split()) for _ in range(t)]

def calc_gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    z = x % y
    return calc_gcd(y, z)

for a,b,c,d in abcd:
    if b > a or b > d:
        print('No')
        continue
    elif c >= b:
        print('Yes')
        continue
    g = calc_gcd(b, d)
    if b - g + (a % g) > c:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    t = I()
    aa = [LI() for _ in range(t)]
    rr = []
    for a,b,c,d in aa:
        if a < b or d < b:
            rr.append('No')
            continue
        if c >= b:
            rr.append('Yes')
            continue
        g = fractions.gcd(b, d)
        if g == 1:
            if b - c > 1:
                rr.append('No')
            else:
                rr.append('Yes')
            continue
        t = (a + d - c) % g
        if t == 0:
            t = g
        if b - c - t > 0:
            rr.append('No')
        else:
            rr.append('Yes')

    return '\n'.join(rr)




print(main())

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import fractions
def solve(a, b, c, d):
    if a < b:
        return False
    if d < b:
        return False
    if b <= c:
        return True
    assert c < b <= min(a, d)
    g = fractions.gcd(b, d)
    return b - g + a % g <= c

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    ans = solve(a, b, c, d)
    print(['No', 'Yes'][ans])

Submission status: Accepted

Solution code:
def gcd(X0,X1):
    Y0=max([X0,X1])
    Y1=min([X0,X1])
    if Y0%Y1==0:
        return Y1
    else:
        return gcd(Y1,Y0%Y1)

def canbuy(A,B,C,D):
    if B>A:
        return False
    elif B>D:
        return False
    elif C>=B:
        return True
    else:
        g=gcd(B,D)
        X=B-g+(A%g)
        if X>C:
            return False
        else:
            return True

T=int(input())
S=["" for i in range(T)]
for i in range(T):
    a,b,c,d=map(int,input().split())
    if canbuy(a,b,c,d):
        S[i]="Yes"
    else:
        S[i]="No"

for i in range(T):
    print(S[i])

Submission status: Accepted

Solution code:
t = int(input())

def gcd(x, y):
    if x > y:
        x, y = y, x
    while x > 0:
        x, y = y%x, x
    return y

for _ in range(t):
    a,b,c,d = map(int, input().split())

    if b > a or b > d:
        print("No")
        continue
    if c >= b:
        print("Yes")
        continue

    a %= b
    g = gcd(b, d)
    if b-g+(a % g) > c:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
import fractions

def func(A,B,C,D):
#	print "A,B,C,D::",A,B,C,D

	if A<B:
		print "No"
	elif B>D:
		print "No"
	elif B<=C:
		print "Yes"

	else:
		A%=B
		g=fractions.gcd(B,D)
		if g==B:
			if A>C:
				print "No"
			else:
				print "Yes"
		elif B-g>C:
			print "No"
		else:
			print "Yes"
T=input()

for i in range(T):
	a,b,c,d=map(int, raw_input().split())
	func(a,b,c,d)

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
for i in range(n):
  a,b,c,d=map(int,input().split())
  g = gcd(b,d)
  print('Yes' if (b//g-1)*g + (a % b) % g<=c and a>=b and d>=b else 'No')

Submission status: Accepted

Solution code:
import sys

def gcd(x, y):
    x, y = sorted([x, y])
    while y % x:
        y, x = x, y % x
    return x

t = int(sys.stdin.readline())
for _ in range(t):
    a, b, c, d = map(int, sys.stdin.readline().split())
    if a < b:
        print("No")
    elif d < b:
        print("No")
    elif c >= b:
        print("Yes")
    else:
        g = gcd(b, d)
        if b - g + (a % g) > c:
            print("No")
        else:
            print("Yes")

Submission status: Accepted

Solution code:
from fractions import gcd

Q = int(input())
qs = []
for _ in range(Q):
	qs.append(list(map(int, input().split())))

for q in qs:
	a, b, c, d = q[0], q[1], q[2], q[3]
	if a < b or b > d:
		print("No")
	elif b <= c:
		print("Yes")
	elif d % b == 0:
		if a % b > c:
			print("No")
		else:
			print("Yes")
	else:
		a = a % b
		d = d % b
		d = gcd(b, d)
		if a > c:
			print("No")
		elif (a + ((c - a) // d) * d + d) % b <= c:
			print("Yes")
		else:
			print("No")

Submission status: Accepted

Solution code:
#coding: utf-8

def getInput():
    in_row = [ int(x) for x in input().split(" ") ]
    return in_row

def gcd(n1, n2):
    while n1 % n2 != 0:
        if n1 < n2:
            n1, n2 = n2, n1
        n1 %= n2
    return n2
            
def judgeTakahashi(in_row):
    A = in_row[0]
    B = in_row[1]
    C = in_row[2]
    D = in_row[3]
    g = gcd(B, D)

    if B > A:
        return False
    if B > D:
        return False
    if C >= B:
        return True
    
    if B-g+(A%g) > C:
        return False
    else:
        return True

if __name__ == "__main__":
    N = int(input())
    assert gcd(1071, 1029) == 21, "error"
    assert not(judgeTakahashi([1, 10, 1, 1])), "error"
    for i in range(N):
        in_row = getInput()
        result = "Yes" if judgeTakahashi(in_row) else "No"
        print(result)

Submission status: Accepted

Solution code:
def gcd( a, b):
    if b == 0:
        return a
    else:
        return gcd( b, a % b)

n = int(input())
list = [map(int, input().split()) for i in range(n)]
 
def check(num):
    a, b, c, d = list[num]
    if a < b:
        return False
    if a % b > c:
        return False
    if b > d:
        return False
    if c < b and d != b:
        if (b - ( a % b ) - 1) // gcd( b, d) != ((c - ( a % b ))) // gcd( b, d):
            return False
    return True
 
for i in range(n):
    if check(i):
        print('Yes')
    else:
        print('No')

Submission status: Accepted

Solution code:
from fractions import gcd
def F(a, b, c, d):
	if a < b or d < b:
		return False
	a -= c
	a %= gcd(b, d)
	if a == 0:
		a = gcd(b, d)
	return a - b >= -c
for t in range(input()):
	a, b, c, d = map(int, raw_input().split())
	print ['No', 'Yes'][F(a, b, c, d)]

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b== 0:
        return a
    else:
        return gcd(b,a%b)

t = int(input())
abcd = []
ans = "No"
for i in range(0,t):
    ABCD = list(map(int,input().split()))
    abcd.append(ABCD)
for a,b,c,d in abcd:
    if a >= b and b==d and b <= c:
        ans = "Yes"
    if a >= b and d >= b and b > c and b - gcd(d,b) + a%gcd(d,b) <= c:
        ans = "Yes"
    if a >= b and d >= b and b <= c:
        ans = "Yes"
    print(ans)
    ans = "No"

Submission status: Accepted

Solution code:
def gcd(a, b):
    a, b  = max(a, b), min(a, b)
    while a%b != 0:
        a, b = b, a%b
    return b

T = int(input())
set = []
for i in range(T):
    set.append([int(j) for j in input().split()])
 
for i in range(T):
    if set[i][0] < set[i][1] or set[i][1] > set[i][3]:
        print("No")
    elif set[i][2] >= set[i][1]:
        print("Yes")
    else:
        g = gcd(set[i][1], set[i][3])
        amodg = set[i][0]%g
        if set[i][1] - g + amodg <= set[i][2]:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
import fractions

def judge(A, B, C, D):
    if A < B:   # そもそも買えない
        return False
    if D < B:   # 補充が間に合わないのでいずれ在庫が尽きる
        return False
    if B <= C:  # 補充が間に合う状況で、必ず0個以上の在庫がある
        return True
    G = fractions.gcd(B, D)   # 昼の買い物の後に残る在庫数の候補のステップ数
    R = A % G       # 例えば A = 3, G = 2の場合、必ず1個あまる
    if C + G - R - B  < 0:
        # C + G - R: 在庫の最小数
        return False
    else:
        return True

T = int(input())
data = []
for _ in range(T):
    data.append([int(xi) for xi in input().split()])
for A, B, C, D in data:
    print('Yes') if judge(A, B, C, D) else print('No')