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:
import math
import fractions
#import sys
#input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ZipArray(a):
    aa = [[a[i],i]for i in range(n)]

    aa.sort(key = lambda x : x[0])
    for i in range(n):
        aa[i][0]=i+1
    aa.sort(key = lambda x : x[1])
    b=[aa[i][0] for i in range(len(a))]
    return b

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans

def Zeros(a,b):
    if(b<=-1):
        return [0 for i in range(a)]
    else:
        return [[0 for i in range(b)] for i in range(a)]

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
            
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))

#################################################
#################################################
#################################################
#################################################



#9:04

n = int(input())

for i in range(n):
    a,b,c,d = list(map(int, input().split()))
    if(b>d or a<b):
        print("No")
        continue
    G = fractions.gcd(b,d)
    minim = a%G
    if(b-G<=c and minim<=c):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from fractions import gcd
import sys
input = sys.stdin.readline

T = int(input())
for _ in range(T):
    A, B, C, D = map(int, input().split())
    if D < B or A < B:
        ans = 'No'
    elif C >= B:
        ans = 'Yes'
    else:
        g = gcd(B, D)
        lb, ub = -10**18, 10**18
        while ub - lb > 1:
            m = (lb + ub) // 2
            if A - g * m > C:
                lb = m
            else:
                ub = m
        if A - g * lb < B:
            ans = 'No'
        else:
            ans = 'Yes'
    print(ans)

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
T=int(input())
from fractions import gcd
for i in range(T):
    A,B,C,D=map(int,input().split())
    if A<B or D<B:
        print("No")
        continue
    if B<=C+1:
        print("Yes")
        continue
    if B==D:
        if A%B<=C:
            print("Yes")
        else:
            print("No")
        continue
    g=gcd(B,D-B)
    if (C-A%g)//g<(B-1-A%g)//g:
        print("No")
    else:
        print("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 b>d:
    print('No')
    continue
  if a<b:
    print('No')
    continue
  g = gcd(b,d)
  x = a-b
  M = ((c-x)//g+1)*g+x
  if M>=b:
    print('Yes')
  else:
    print('No')

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 b>d:
    print('No')
    continue
  if a<b:
    print('No')
    continue
  if c>b:
    print('Yes')
    continue
  g = gcd(b,d)
  x = a-b
  M = ((c-x)//g+1)*g+x
  if M>=b:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
from fractions import gcd
for i in range(int(input())):
    a,b,c,d=map(int,input().split())
    g=gcd(b,d)
    r=a%g
    if r>=b-d and c>=b-(g-r) and a>=b:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

n = int(input())
C = [list(map(int,input().split())) for i in range(n)]

from fractions import gcd

for i in range(n):
    a = C[i][0]
    b = C[i][1]
    c = C[i][2]
    d = C[i][3]
    ng = 0

    e = 0  # 最初に補充が発生する直前の本数
    e0 = a - b
    e1 = ((c - a%b) // b) * b + a%b
    e = min(e0, e1)

    if e < 0 or b > d:
        ng = 1
    else:
        g = gcd(b, d)
        # print(c+1, b-1, g)
        if c+1 <= b-1 and (c - e) // g < (b-1 - e) // g:
            ng = 1

    if ng == 1:
        print("No")
    else:
        print("Yes")

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 A < B or D < B:
    print('No')
  else:
    a = A % B
    if a > C:
      print('No')
    else:
      if 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:
import fractions

T = int(input())

def solve(A, B, C, D):
    left = A
    if A < B:
        print('No')
        return
    if D < B:
        print('No')
        return
    if C >= B:
        print('Yes')
        return
    g = fractions.gcd(B, D)
    max_mod_b = B - g + (A % g)
    if max_mod_b > C:
        print('No')
    else:
        print('Yes')

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

Submission status: Accepted

Solution code:
T=int(input())
ABCD=[list(map(int,input().split())) for i in range(T)]
from fractions import gcd
def f(a):
    print(['No','Yes'][a])
for a,b,c,d in ABCD:
    if a<b:f(0)
    elif d<b:f(0)
    elif b<=c:f(1)
    else:
        g=gcd(b,d)
        h=a%b
        f(max(((b-h)//g*g+h)%b,b-g)<=c)

Submission status: Accepted

Solution code:
import fractions
t = int(input())
al = []
for i in range(t):
    a,b,c,d = map(int,input().split())
    if b > d:
        al.append("No")
    else:
        if b > a:
            al.append("No")
        else:
            if b-1 <= c:
                al.append("Yes")
            else:
                if a % b > c:
                    al.append("No")
                else:
                    yo = d%b
                    now = a%b 
                    if yo == 0:
                        al.append("Yes")
                    else:
                        g = fractions.gcd(b,yo)
                        #print(g)
                        if c >= b-g+a%g:
                            al.append("Yes")
                        else:
                            al.append("No")
for i in al:
    print(i)

Submission status: Accepted

Solution code:
t = int(input())

import fractions

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

    if(b > d)|(a < b):
        print('No')
        continue

    if(b <= c):
        print('Yes')
        continue

    c1 = a - (1+(a-c-1)//b)*b
    if(c1 < 0):
        print('No')
        continue

    mod = fractions.gcd(b,d)
    red = c1 % mod

    for i in [0,1]:
        tmp = ((c//mod) + i)*mod + red
        if(c < tmp < b):
            print('No')
            break

        if(i==1):
            print('Yes')

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

import fractions

T = I()
A,B,C,D = LIR(T,4)

for i in range(T):
    if A[i] < B[i]:
        print('No')
        continue

    g = fractions.gcd(B[i],D[i])

    # 0~B-1に突入する際の最小値と最大値を求める
    x = (A[i]%B[i])//g
    min_ = (A[i]%B[i]) - x*g

    x = (B[i]-1-(A[i]%B[i])) // g
    max_ = (A[i]%B[i]) + x*g

    if max_ > C[i] or min_ < B[i]-D[i]:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
# 解説AC
from fractions import gcd
def judge(A,B,C,D):
    """
    在庫数をXとする。
    C < X < B のときFalse
    p,qを0以上の整数とすると、
    X = A + D * p - B * q 
    X = A % G + k * G

    C + 1 <= X
    -> k = ceil((C + 1 - A % G) / G)
    """

    if A < B: return False
    if D < B: return False
    if C >= B: return True
    
    G = gcd(B, D)
    k = (C - (A % G) + G) // G
    return False if ((A % G + k * G) < B) else True

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

Submission status: Accepted

Solution code:
# 解説AC
from fractions import gcd
def judge(A,B,C,D):
    if A < B: return False
    if D < B: return False
    if C >= B: return True
    
    g = gcd(B, D)

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

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

Submission status: Accepted

Solution code:
T = int(input())

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

while T:
  T -= 1
  
  A, B, C, D = map(int, input().split())
  
  if B > A or B > D:
    print("No")
  else:
    p = A - (A - C + B - 1) // B * B
    r = D % B
    g = gcd(r, B - r)
    if p < 0:
      print("No")
    elif r == 0 or (C - r - p + g) // g * g + p - B + r >= 0:
      print("Yes")
    else:
      print("No")

Submission status: Accepted

Solution code:
from fractions import gcd
def main():
    T=int(input())
    for _ in range(T):
        A,B,C,D=map(int, input().split())
        ans=True
        if B>D or B>A:
            ans=False
        elif B<=C:
            pass
        else:
            i=A%B
            if C<i:
                ans=False
            g=gcd(B,D)
            if g and not ((C-i)//g*g+i<=C and B<=(C-i)//g*g+i+g):
                ans=False
        print("YNeos"[not ans::2])

if __name__ == "__main__":
    main()

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 b>d:
    print('No')
  elif b>a:
    print('No')
  elif c>=b:
    print('Yes')
  elif b==d:
    if a%b<c:
      print('Yes')
    else:
      print('No')
  else:
    m = d%b
    n = a%b
    g = gcd(b,d)
    if b-g+(a%g)>c:
      print('No')
    else:
      print('Yes')

Submission status: Accepted

Solution code:
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

T = ir()

def check(a, b, c, d):
    if a < b or d < b:
        answer = 'No'
    # 以降 d >= b とする
    elif c >= b:
        answer = 'Yes'
    else:
        a %= b; d %= b
        # c < x < b の間に個数が入ると'No'
        g = gcd(b, d)
        if b - g + (a % g) > c:
            answer = 'No'
        else:
            answer = 'Yes'
    print(answer)

for _ in range(T):
    check(*lr())

# 16

Submission status: Accepted

Solution code:
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import fractions
t = inn()
for i in range(t):
    a,b,c,d = inm()
    if a<b or d<b:
        print('No')
    else:
        g = fractions.gcd(b,d)
        r = a%g
        q = c%g
        p = c-q+r
        if p<=c:
            p += g
        #ddprint(f"a {a} b {b} c {c} d {d} g {g} r {r} q {q} p {p}")
        if p>=b:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
#00:33
t = int(input())
for _ in range(t):
  a,b,c,d = map(int,input().split())
  if d - b < 0:
    print('No')
    continue
  if a - b < 0:
    print('No')
    continue
  big = int(b)
  sml = int(d)
  while sml != 0:
    big,sml = sml,big%sml
  gcd = big
  r = (a-c-1) % gcd + 1
  if r + c >= b:
    print('Yes')
  else:
    print('No')

Submission status: Accepted

Solution code:
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy

T=int(input())
ABCD=[list(map(int,input().split())) for i in range(T)]
for A,B,C,D in ABCD:
    if B>D or A<B:
        print("No")
    elif B==D:
        if A%B<=C:
            print("Yes")
        else:
            print("No")
    else:
        E=B-C-1
        if E>0:
            F=D-B
            if E>F:
                print("No")
            else:
                _gcd=gcd(F,B)
                st=(A-B)%_gcd
                #if A==14 and B==10 and C==8 and D==12:
                #    print(B-C-1)
                if B-_gcd+A%_gcd>C:
                    print("No")
                else:
                    print("Yes")
        else:
            print("Yes")

Submission status: Accepted

Solution code:
from bisect import *
from collections import *
from fractions import gcd
from math import factorial
from itertools import *
from heapq import *
import copy

T=int(input())
ABCD=[list(map(int,input().split())) for i in range(T)]
for A,B,C,D in ABCD:
    if B>D or A<B:
        print("No")
    elif C>=B:
        print("Yes")
    else:
        F=D-B
        _gcd=gcd(D,B)
        st=(A-B)%_gcd
        #if A==14 and B==10 and C==8 and D==12:
        #    print(B-C-1)
        if B-_gcd+A%_gcd>C:
            print("No")
        else:
            print("Yes")

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 < 0:
    print("No")
    continue
  if b > d:
    print("No")
    continue
  g = gcd(b, d)
  s = a + (c - a) // b * b
  if s < 0:
    print("No")
    continue
  #print((((b - s - 1) // g) * g + s) % b, s, g)
  if (((b - s - 1) // g) * g + s) % b > c: print("No")
  else: print("Yes")

Submission status: Accepted

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

import sys
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            # 下を探しに行く
            ok = mid
        else:
            # 上を探しに行く
            ng = mid
    return ok

def bisearch_max(mn, mx, func):
    """ 条件を満たす最大値を見つける二分探索 """

    ok = mn
    ng = mx
    while ok+1 < ng:
        mid = (ok+ng) // 2
        if func(mid):
            # 上を探しに行く
            ok = mid
        else:
            # 下を探しに行く
            ng = mid
    return ok

for _ in range(INT()):
    a, b, c, d = MAP()

    # そもそも無理
    if a < b or d < b:
        No()
        continue
    
    # b個減ってd個増える繰り返しなので、このgより細かく値が動くことはない
    g = gcd(b, d)

    # cより大きくてb未満が存在するかどうか
    mn = bisearch_min(-INF, INF, lambda m: a%g + g*m > c)
    mx = bisearch_max(-INF, INF, lambda m: a%g + g*m < b)
    if mn > mx:
        Yes()
    else:
        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 a < b or 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:
def examA():
    N = I()
    A = LI()
    ans = 0
    for i in range(N-1):
        if A[i+1]==A[i]:
            A[i+1] = 101
            ans +=1
    print(ans)
    return

def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x
def examB():
    T = I()
    for i in range(T):
        ans = "Yes"
        A, B, C, D = LI()
        if A<B:
            ans = "No"
        elif D<B:
            ans = "No"
        elif C>=B:
            print(ans)
            continue
        elif B-C>gcd(D,B):
            ans = "No"
        if (A % B) > C:
            ans = "No"
        print(ans)
    return

def examC():
    N = I()
    S = SI()
    d1 = defaultdict(int)
    d2 = defaultdict(int)
    loop = 2**N
    for i in range(loop):
        curR = ""; curB = ""
        curR2 = ""; curB2 = ""
        for j in range(N):
            if i&(1<<j)==(1<<j):
                curR +=S[j]
                curR2 +=S[j+N]
            else:
                curB +=S[j]
                curB2 +=S[j+N]
        d1[(curR,curB)] +=1
        d2[(curR2,curB2)] +=1
    ans = 0
    for key,i in d1.items():
        cur = i*d2[(key[1][::-1],key[0][::-1])]
        ans +=cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examB()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
def gcds(*numbers):
  return reduce(gcd, numbers)
n = int(input())
for i in range(n):
  a,b,c,d = map(int,input().split())
  x = gcds(a,b,c,d)
  if x != 1:
    a = a//x
    b = b//x
    c = c//x
    d = d//x
  if b>d or a<b:
    print("No")
  elif c>=b-1:
    print("Yes")
  elif gcd(b,d) != 1:
    y = gcd(b,d)
    if b-c<y and c%y >= a%y:
        print("Yes")
    else:
      print("No")
  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 D < B or A < B:
        print("No")
        continue
    x = A - (A-C+B-1) // B * B
    g = gcd(B, D)
    l = (C - x) % g
    if C - B + g - l >= 0:
        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 or d < b:
        print ("No")
        continue

    elif b-c < 2:
        print ("Yes")
        continue

    elif (((a-b) % fractions.gcd(b,d-b)) + b - fractions.gcd(b,d-b) > c and ((a-b) % fractions.gcd(b,d-b)) + b - fractions.gcd(b,d-b) < b):
        print ("No")

    else:
        print ("Yes")

Submission status: Accepted

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

T=int(input())
for _ in range(T):
    A,B,C,D=map(int,input().split())
    if D<B:
        print("No")
        continue
    if A<B:
        print("No")
        continue
    if C>=B:
        print("Yes")
        continue
    a=A%B
    d=D%B
    g=gcd(d,B)
    k=(C-a)//g
    if a+(k+1)*g>=B:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

# 一部の自明なケースを除くと、ループする
# [(C+1)-B,C+(D-B)]
# この範囲に0未満の値があって、取ることが可能ならNoである

# 2つの変化(-B),(D-B)は、まとめて-B(mod D)と捉える
# ループ区間で、
# g=gcd(D,B)を法として、
# Aと合同なXは、すべて取ることができる(らしい)

# 0未満の値を取れるならNoである
# gを法として、Aと合同なXのうち、0以上の最小値は、
# A%gと表せるので、
# gを法として、Aと合同なXのうち、0未満の最大値は、
# (A%g)-gである
# [(C+1)-B,0)に(A%g)-gが含まれるならNoである

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


def judge(A, B, C, D):
    """A:初期値,B:減少量,C以下で増加,D増加量"""
    if (B > A) or (B > D):
        # 減る
        # 初回購入できない/増加が追い付かない
        return False

    if B <= C:
        # 増える
        # C以下の値は一度に削りきらないと増加してしまうが、削り切れない
        return True

    # ループ
    # (C < B) and (B <= A) and (B <= D)
    g = gcd(B, D)
    a = A % g
    return a - g < C + 1 - B
    # ループ範囲は、C+1-B以上なので、
    # gを法として、Aと合同な値のうち、0未満で最大の値a-gが
    # C+1-B未満なら、ループ範囲に0未満の値は含まれず、無限にジュースを飲める


T = int(input())
for _ in range(T):
    bl = judge(*map(int, input().split()))
    print('Yes' if bl else 'No')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from fractions import gcd
def resolve():
    for _ in range(int(input())):
        a,b,c,d=map(int,input().split())
        if(a<b):
            print("No")
            continue
        if(b>d):
            print("No")
            continue
        if(c>=b):
            print("Yes")
            continue

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

Submission status: Accepted

Solution code:
from fractions import gcd
for _ in range(int(input())):
 a,b,c,d=list(map(int,input().split()))
 k,p=b*max((a-c-1)//b+1,1),0
 if d<b or a<k:p=1
 elif b<c+2:p=0
 elif b-c>gcd(b,d):p=1
 print("YNeos"[p::2])

Submission status: Accepted

Solution code:
def main():
    from fractions import gcd
    n=int(input())
    for _ in range(n):
        a,b,c,d=list(map(int,input().split()))
        if a<b or b>d:
            print("No")
            continue
        k=(a-c-1)//b+1
        e=a-b*k
        if e<0:
            print("No")
            continue
        if b<=c+1 and b<=d:
            print("Yes")
            continue
        g=gcd(b,d)
        if b-c>g:
            print("No")
        else:
            print("Yes")
main()

Submission status: Accepted

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

_, *Q = map(int, open(0).read().split())
for a, b, c, d in zip(*[iter(Q)] * 4):
	if a < b or d < b:
		print("No")
		continue
	if c >= b:
		print("Yes")
		continue
	a %= b
	g = gcd(b, d)
	# b - g + a - g * (a // g) < b
	if b - g + a - g * (a // g) > c:
		print("No")
	else:
		print("Yes")

Submission status: Accepted

Solution code:
from fractions import gcd
_, *Q = map(int, open(0).read().split())
for a, b, c, d in zip(*[iter(Q)] * 4):
	if a < b or d < b:
		print("No")
		continue
	if c >= b:
		print("Yes")
		continue
	a %= b
	g = gcd(b, d)
	# b - g + a - g * (a // g) < b
	if b - g + a - g * (a // g) > c:
		print("No")
	else:
		print("Yes")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from fractions import gcd

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

def solve(A, B, C, D):
    if A < B or D < B:
        return False
    if C < B-1:
        if D%B != 0:
            cycle = gcd(D, B)
            if C < B-cycle:
                return False
            if A%cycle < (C+1)%cycle:
                return True
            else:
                return False
        else:
            if A%B <= C:
                return True
            else:
                return False
    else:
        return True

for A, B, C, D in Query:
    ans = "Yes" if solve(A, B, C, D) else "No"
    print(ans)

Submission status: Accepted

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

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

def solve(A, B, C, D) :
    if B > A or B > D :
        return 'No'
        
    a0 = A % B
    d = gcd(B, D)
    if a0 + ((C - a0) // d + 1) * d >= B :
        return 'Yes'
        
    return 'No'

for A, B, C, D in ABCD :
    print(solve(A, B, C, D))

Submission status: Accepted

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

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

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

t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    if solve(a, b, c, d):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from fractions import*
_,*t=open(0)
for t in t:a,b,c,d=map(int,t.split());print('YNeos'[b>min(a,d)or~a%gcd(b,d)-b<~c::2])

Submission status: Accepted

Solution code:
from fractions import*;_,*t=open(0)
for t in t:a,b,c,d=map(int,t.split());print('YNeos'[b>min(a,d)or~a%gcd(b,d)-b<~c::2])

Submission status: Accepted

Solution code:
from fractions import*;_,*t=open(0)
for t in t:a,b,c,d=map(int,t.split());print('YNeos'[b>min(a,d)or~(~a%gcd(b,d))+b>c::2])

Submission status: Accepted

Solution code:
from fractions import*
_,*t=open(0)
for t in t:
  a,b,c,d=map(int,t.split())
  print('YNeos'[b>min(a,d)or~(~a%gcd(b,d))+b>c::2])

Submission status: Accepted

Solution code:
from fractions import*;exec("a,b,c,d=map(int,input().split());g=gcd(b,d);print('YNeos'[b>min(a,d)or b-g+a%g>c::2]);"*int(input()))

Submission status: Accepted

Solution code:
from fractions import*
_,*t=open(0)
for t in t:
  a,b,c,d=map(int,t.split())
  g=gcd(b,d)
  print('YNeos'[b>min(a,d)or b-g+a%g>c::2])

Submission status: Accepted

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

def solve(a, b, c, d):
    if a < b or d < b:
        return False
    if b < c:
        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):
    print(("No", "Yes")[solve(*t)])

Submission status: Accepted

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

def solve(a, b, c, d):
    if a < b or d < b:
        return False
    if b < c:
        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):
    print("Yes" if solve(*t) else "No")

Submission status: Accepted

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

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

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

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

print("\n".join("Yes" if solve(*t) else "No" for t in  zip(*[iter(L)] * 4)))

Submission status: Accepted

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

def solve(a, b, c, d):
    if a < b or d < b:
        return False
    if b < c:
        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:
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

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 b < c:
        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:
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

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:
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

T = int(input())

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

    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

T = int(input())

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

    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")