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: Wrong Answer

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 <= 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")
                    elif now == 0:
                        g = fractions.gcd(b,yo)
                        if b - g <= c:
                            al.append("Yes")
                        else:
                            al.append("No")
                    else:
                        g = fractions.gcd(yo,now)
                        g = fractions.gcd(g,b)
                        if b - g <= c:
                            al.append("Yes")
                        else:
                            al.append("No")
for i in al:
    print(i)

Submission status: Wrong Answer

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 = math.floor((A[i]%B[i])/g)
    min_ = (A[i]%B[i]) - x*g

    x = math.floor((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: Wrong Answer

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: Wrong Answer

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 True if (B - g + (A % g) > C) else False

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: Wrong Answer

Solution code:
def judge(A,B,C,D):
    if (A - B < 0) or (D - B < 0): return False
    if C - B >= 0: return True
    if D - B == 0:
        n = (A - C - 1) // B
        return True if (0 <= (A - B) - B * n) else False

    # 初項(A-B) 公差(D-B)の等差数列a
    # a: C以上となる数
    n = (C - A - B + 2 * D) // (D - B)
    a = (A - B) + (n - 1) * (D - B)
    return a >= B

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

Submission status: Wrong Answer

Solution code:
def judge(A,B,C,D):
    if (A - B < 0) or (D - B < 0):
        return False
    if D - B == 0:
        n = (A - C - 1) // B
        return True if (0 <= (A - B) - B * n) else False

    # 初項(A-B) 公差(D-B)の等差数列a
    # a: C以上となる数
    n = (C - A - B + 2 * D) // (D - B)
    a = (A - B) + (n - 1) * (D - B)
    return a >= B

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

Submission status: Wrong Answer

Solution code:
def judge(A,B,C,D):
    if (A - B < 0) or (D - B < 0):
        return False
    if D - B == 0:
        n = (A - C - 1) // B
        return True if (0 <= (A - B) - B * n) else False

    # 初項(A-B) 公差(D-B)の等差数列a
    # a: C以上となる数
    n = (C - A - B + 2 * D) // (D - B)
    a = (A - B) + (n - 1) * (D - B)
    print(n,a)
    return a >= B

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

Submission status: Wrong Answer

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 - p) // g * g + p - B + r >= 0:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

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 a

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 - p) // r * r + p - B + r >= 0:
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
T = int(input())

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
    if p < 0:
      print("No")
    elif p >= 0 and (r == 0 or ((C + r - p) // r) * r + p - B >= 0):
      print("Yes")
    else:
      print("No")

Submission status: Wrong Answer

Solution code:
T = int(input())

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

Submission status: Wrong Answer

Solution code:
T = int(input())
for _ in range(T):
    A,B,C,D = map(int, input().split())
    if B > D or B > A:
        ans = "No"
    elif B <= C+1:
        ans = "Yes"
    elif B == D:
        A %= B
        if C < A < B:
            ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "Yes"
        for _ in range(10000):
            x = max(0, (B+C-A)//(D-B)+1)
            A += x*(D-B)
            y = max(0, (A-C+B-1)//B-1)
            A -= y*B
            if A < B:
                ans = "No"
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
T = int(input())
for _ in range(T):
    A,B,C,D = map(int, input().split())
    if B > D or B > A:
        ans = "No"
    elif B <= C+1:
        ans = "Yes"
    elif B == D:
        A %= B
        if C < A < B:
            ans = "No"
        else:
            ans = "Yes"
    else:
        ans = "Yes"
        for _ in range(100):
            x = max(0, (B+C-A)//(D-B)+1)
            A += x*(D-B)
            y = max(0, (A-C+B-1)//B-1)
            A -= y*B
            if A < B:
                ans = "No"
                break
    print(ans)

Submission status: Wrong Answer

Solution code:
T = int(input())
for _ in range(T):
    A,B,C,D = map(int, input().split())
    if B > D or B > A:
        ans = "No"
    elif B <= C+1:
        ans = "Yes"
    elif B == D:
        A %= B
        if C < A < B:
            ans = "No"
        else:
            ans = "Yes"
    else:
        x = (A-C-1)//B
        A -= x*B
        y = int((B+C-A)/(D-B))+1
        A += y*(D-B)-B
        z = max(int((B+C-A)/(D-B))+1, 1)
        if A >= B and z*(D-B) >= B:
            ans = "Yes"
        else:
            ans = "No"
    print(ans)

Submission status: Wrong Answer

Solution code:
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
    x = ((b-a%b)//m)*m+a%b
#    print(a,b,c,d,x)
    if x%b==0:
      x = (-m)%b
    if c<x:
      print('No')
    else:
      print('Yes')

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

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:
        print('No')
    elif c >= b:
        print('Yes')
    else:
        a %= b
        if d > b:
            d %= b
            d += b        
        X = np.array([a] + [d] * 10 ** 4)
        Xcum = (X.cumsum() % b)
        Xcum[Xcum<=c] += d
        bool = np.any(Xcum < b)
        print('No' if bool else 'Yes')

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

# 10

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

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:
        print('No')
    else:
        a %= b
        if d > b:
            d %= b
            d += b        
        X = np.array([a] + [d] * 10 ** 4)
        Xcum = (X.cumsum() % b)
        Xcum[Xcum<=c] += (d % b)
        bool = np.any(Xcum < b)
        print('No' if bool else 'Yes')

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

# 10

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

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, i):
    if a < b or d < b:
        print('No')
    else:
        a %= b
        if d > b:
            d %= b
            d += b        
        X = np.array([a] + [d] * 10 ** 4)
        Xcum = (X.cumsum() % b)
        Xcum[Xcum<=c] += d
        bool = np.any(Xcum < b)
        print('No' if bool else 'Yes')

for i in range(T):
    check(*(lr() + [i]))

# 10

Submission status: Wrong Answer

Solution code:
from math import sqrt

T = int(input())
for _ in range(T):
  A,B,C,D = list(map(int, input().split()))
  # 初日にゼロ、もしくは補給よりも消費が多い。
  if A < B or B > D:
    print("No")
    continue
  # 補給が必ずまにあう
  if 2*B <= C:
    print("Yes")
    continue
  flg = True
  histo = set()
  for i in range(1000):
    #print(i,A, A%B, A%B <= C, A%B+D)
    A = A%B+D
    if A in histo:
      break
    else:
      histo.add(A)
      
    if A%B > C:
      print("No")
      flg = False
      break
  if flg:
    print("Yes")

Submission status: Wrong Answer

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
        g=gcd(D,B)
        if (B-A%g)-(B-A%g)%g+A%g>C:
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

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-A%_gcd)//_gcd)*_gcd+A%_gcd>C:
            print("No")
        else:
            print("Yes")

Submission status: Wrong Answer

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
                end1,end2=C+1,B-1
                end1%=_gcd
                end2%=_gcd
                if end1<=end2:
                    if end1<=st<=end2:
                        print("No")
                    else:
                        print("Yes")
                else:
                    if end1<=st<=_gcd-1 or 0<=st<=end2:
                        print("No")
                    else:
                        print("Yes")
        else:
            print("Yes")

Submission status: Wrong Answer

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:
        _gcd=gcd(D-B,B)
        st=(A-B)%_gcd
        #if A==14 and B==10 and C==8 and D==12:
        #    print(B-C-1)
        end1,end2=C+1,B-1
        end1%=_gcd
        end2%=_gcd
        if end1<=end2:
            if end1<=st<=end2:
                print("No")
            else:
                print("Yes")
        else:
            if end1<=st<=_gcd-1 or 0<=st<=end2:
                print("No")
            else:
                print("Yes")

Submission status: Wrong Answer

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(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")
        else:
            print("Yes")

Submission status: Wrong Answer

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: Wrong Answer

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(D,B)
                st=(A-B)%_gcd
                #if A==14 and B==10 and C==8 and D==12:
                #    print(B-C-1)
                if B-C-1>=_gcd:
                    print("No")
                else:
                    end1,end2=C+1,B-1
                    end1%=_gcd
                    end2%=_gcd
                    if end1<=end2:
                        if end1<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
                    else:
                        if end1<=st<=_gcd-1 or 0<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
        else:
            print("Yes")

Submission status: Wrong Answer

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-C-1>=_gcd:
                    print("No")
                else:
                    end1,end2=C+1,B-1
                    end1%=_gcd
                    end2%=_gcd
                    if end1<=end2:
                        if end1<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
                    else:
                        if end1<=st<=_gcd-1 or 0<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
        else:
            print("Yes")

Submission status: Wrong Answer

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 B>C:
            F=D-B
            if E>F:
                print("No")
            else:
                _gcd=gcd(F,A)
                st=(A-B)%_gcd
                #if A==14 and B==10 and C==8 and D==12:
                #    print(B-C-1)
                if B-C-1>=_gcd:
                    print("No")
                else:
                    end1,end2=C+1,B-1
                    end1%=_gcd
                    end2%=_gcd
                    if end1<=end2:
                        if end1<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
                    else:
                        if end1<=st<=_gcd-1 or 0<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
        else:
            print("Yes")

Submission status: Wrong Answer

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,A)
                st=(A-B)%_gcd
                #if A==14 and B==10 and C==8 and D==12:
                #    print(B-C-1)
                if B-C-1>=_gcd:
                    print("No")
                else:
                    end1,end2=C+1,B-1
                    end1%=_gcd
                    end2%=_gcd
                    if end1<=end2:
                        if end1<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
                    else:
                        if end1<=st<=_gcd-1 or 0<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
        else:
            print("Yes")

Submission status: Wrong Answer

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,A)
                st=(A-B)%_gcd
                #if A==14 and B==10 and C==8 and D==12:
                #    print(B-C-1)
                if B-C-1>=_gcd:
                    print("No")
                else:
                    end1,end2=C+1,B-1
                    end1%=_gcd
                    end2%=_gcd
                    if end1<=end2:
                        if end1<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
                    else:
                        if end1<=st<=F-1 or 0<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
        else:
            print("Yes")

Submission status: Wrong Answer

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,A)
                st=(A-B)%_gcd
                #if A==14 and B==10 and C==8 and D==12:
                #    print(B-C-1)
                if B-C-1>=_gcd:
                    print("No")
                else:
                    end1,end2=C+1,B-1
                    end1%=F
                    end2%=F
                    if end1<=end2:
                        if end1<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
                    else:
                        if end1<=st<=F-1 or 0<=st<=end2:
                            print("No")
                        else:
                            print("Yes")
        else:
            print("Yes")

Submission status: Wrong Answer

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 d%b == 0:
    if a<=c:
      print("Yes")
    elif a%b<=c:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
def modrep(x, b, count, c, d):
  for _ in range(count):
    g = x % b
    if g > c:
      return False
    if x < b:
      return False
    x = g + d
  return True
for _ in range(N):
  a, b, c, d = map(int, input().split())
  g = a % b + (c // b) * b
  if a < b:
    print("No")
    continue
  if g > c:
    print("No")
    continue
  #print(g, b)
  if modrep(g + d, b, 10000, c, d) == False:
    print("No")
    continue
  print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
def modrep(x, b, count, c, d):
  for _ in range(count):
    g = x % b
    if g > c:
      return False
    if x < b:
      return False
    x = g + d
  return True
for _ in range(N):
  a, b, c, d = map(int, input().split())
  g = (c // b) * b
  if a < b:
    print("No")
    continue
  if g == 0 and (a % b):
    print("No")
    continue
  if modrep(g + d, b, 10000, c, d) == False:
    print("No")
    continue
  print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
def modrep(x, b, count, c, d):
  for _ in range(count):
    g = x % b
    if g > c:
      return False
    if x < b:
      return False
    x = g + d
  return True
for _ in range(N):
  a, b, c, d = map(int, input().split())
  g = a % b
  if a < b:
    print("No")
    continue
  if g > c:
    print("No")
    continue
  #print(g, b)
  if modrep(g + d, b, 10000, c, d) == False:
    print("No")
    continue
  print("Yes")

Submission status: Wrong Answer

Solution code:
t = int(input())
for i in range(t):
    a, b, c, d = map(int, input().split())
    if a < b:
        print('No')
    elif b > d:
        print('No')
    elif b == d:
        print('Yes' if a % b <= c else 'No')
    elif b < d:
        p = max(1, (a - c + b - 1) // b)
        q = a - p * b
        x = c - q
        y = d - b
        n = x // y + 1
        m = (a - b) + n * (d - b)
        if q < 0 or x < 0 or m < b:
            print('No')
        else:
            print('Yes')

Submission status: Wrong Answer

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
        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: Wrong Answer

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

for A, B, C, D in ABCD :
    a0 = A - (A - C + B - 1) // B * B
    if a0 < 0 or A < B or D < B :
        print('No')
    elif B - C >= 2 and D > B :
        d = D - B
        # C以下で最大のものを見つける
        ac = (C - a0) // d * d + a0
        if ac < 0 or ac + d < B :
            print('No')
        else :
            print('Yes')
    else :
        print('Yes')

Submission status: Wrong Answer

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

for A, B, C, D in ABCD :
    a0 = A - (A - C + B - 1) // B * B
    if a0 < 0 :
        print('No')
    elif A < B :
        print('No')
    elif D < B :
        print('No')
    elif B - C >= 2 and D > B :
        d = D - B
        # C以下で最大のものを見つける
        ac = (C - a0) // d * d + a0
        if ac + d < B :
            print('No')
        else :
            print('Yes')
    else :
        print('Yes')

Submission status: Wrong Answer

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

for A, B, C, D in ABCD :
    a0 = A - (A - C + B - 1) // B * B
    if a0 < 0 :
        print('No')
    elif A < B :
        print('No')
    elif D < B :
        print('No')
    elif B - C >= 2 and D > B :
        d = D - B
        # C以下で最大のものを見つける
        ac = (C - a0) // d * d + a0
        if ac + d < B :
            print('No', a0, d, ac)
        else :
            print('Yes', a0, d, ac)
    else :
        print('Yes')