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: Time Limit Exceeded

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

def check(a,b,c,d):
    if b > d or a < b:
        print("No")
        return
    elif c >= b:
        print("Yes")
        return
    def_a = a % b
    a = def_a
    while True:
        a = (a + d) % b
        if a > c:
            print("No")
            return
        elif def_a == a:
            print("Yes")
            return

for abcd in ABCD:
    check(abcd[0],abcd[1],abcd[2],abcd[3])

Submission status: Time Limit Exceeded

Solution code:
#B
T=int(input())
for i in range(T):
    A,B,C,D=map(int,input().split())
    A_list=[]
    while True:
        A-=B
        if A<0:
            print('No')
            break
        elif A<=C:
            A+=D
            if A in A_list:
                print('Yes')
                break
            A_list.append(A)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
def solve():
    a, b, c, d = map(int, input().split())
    if a < b or d < b:
        return 'No'
    cache = set()
    while True:
        a %= b
        if c < a < d:
            return 'No'
        a += (d - b)
        if a in cache:
            return 'Yes'
        cache.add(a)

T = int(input())
for _ in range(T):
    print(solve())

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
r = []
for i in range(t):
    a,b,c,d = map(int, input().split())
    m = []
    a = min(a, a % b + b * ((b // c) + 1))
    while b <= a:
        m.append(a)
        a -= b
        if a <= c:
            a += min(d, b + d % b)
        if a in m:
            break
    if a in m:
        r.append('Yes')
    else:
        r.append('No')

print('\n'.join(r))

Submission status: Time Limit Exceeded

Solution code:
T=int(input())
for _ in range(T):
    a,b,c,d=map(int, input().split())
    switch=0
    n=a-b
    while True:
        if n<0:
            print("No")
            break
        elif n==a-b and switch==1:
            print("Yes")
            break
        else:
            if n<=c: n = n+d-b
            else: n = n-b
            switch=1

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def check(a,b,c,d):
    z = a
    if a < b:
        ans = 'No'
        return ans
    z_list = [z]
    for k in range(10000000):
        x = (z - c)//b
        if x <= 0:
            x = 1
        z = z - b * x
        if z < 0:
            ans = 'No'
            break
        if z <= c:
            z += d
        
        if z in z_list:
            ans = 'Yes'
            break
        z_list.append(z)
#         print(z)
    return ans



t = int(input())
a = []
b = []
c = []
d = []
for k in range(t):
    aa,bb,cc,dd = list(map(int,input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)
    d.append(dd)

aa = a
bb = b
cc = c
dd = d

for a,b,c,d in zip(aa,bb,cc,dd):
    ans = check(a,b,c,d)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(T, Q):

    def slv2(A, B, C, D):
        error_print(A, B, C, D)
        if A < B:
            # error_print('A')
            return 'No'

        if D < B:
            # error_print('D')
            return 'No'

        if C >= B:
            return 'Yes'

        s = set([])
        while True:
            # error_print(A)
            if A in s:
                return 'Yes'
            s.add(A)
            if A < B:
                # error_print('No')
                return 'No'

            A %= B
            if A <= C:
                A += D
        return 'Yes'

    a = []
    for q in Q:
        a.append(slv2(*q))

    return '\n'.join(a)


def main():
    T = read_int()
    Q = [read_int_n() for _ in range(T)]
    print(slv(T, Q))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def calc():
    a, b, c, d = map(int, raw_input().split())
    if a < b:
        return 'No'
    if d < b:
        return 'No'
    if c >= b:
        return 'Yes'
    a %= b
    s = set()
    while a not in s:
        s.add(a)
        a = (a + d) % b
        if a > c:
            return 'No'
    return 'Yes'


def main():
    t = input()
    for _ in range(t):
        print calc()


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(T, Q):

    def slv2(A, B, C, D):
        error_print(A, B, C, D)
        if A < B:
            error_print('A')
            return 'No'

        if D < B:
            error_print('D')
            return 'No'

        if C >= B:
            return 'Yes'

        s = set([])
        while True:
            error_print(A)
            if A in s:
                return 'Yes'
            s.add(A)
            if A < B:
                error_print('No')
                return 'No'

            A %= B
            if A <= C:
                A += D
        return 'Yes'

    a = []
    for q in Q:
        a.append(slv2(*q))

    return '\n'.join(a)


def main():
    T = read_int()
    Q = [read_int_n() for _ in range(T)]
    print(slv(T, Q))


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
for i in range(t):
    a,b,c,d = map(int, input().split())
    lis = []
    flag = True
    while a:
        if a >= b:
            a = a%b
        else:
            break
        if a <= c:
            a += d
        if a in lis:
            print("Yes")
            flag = False
            break
        lis.append(a)
    if flag:
        print("No")

Submission status: Accepted

Solution code:
import math

t = int(input())

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

    if b > d:
        # 増える本数より減る本数のほうが多いので、ジュースの本数は目減りしていつか無くなる
        print('No')
        continue
    if a < b:
        # 初日に買おうとしたらないパターン
        print('No')
        continue
    if b == d:
        # 増える本数と減る本数が同じ。一往復が可能なら永遠にループする

        if a <= c:
            # 初日に買えることは確定、その後無限ループに入る
            print('Yes')
            continue

        diff = a-c
        buy_num = (diff + b - 1) // b
        if a - buy_num * b < 0:
            print('No')
            continue
        else:
            print('Yes')
            continue
    
    if b < d:
        # 補題
        # 減少幅b と増加幅dが互いに素であれば、無限回の操作の中で取りうる最小値はc-b+1である。
        # （開店時の値の中で取りうる最小値はc+1である、のほうが分かりやすいかも?）
        # 証明：
        # (1) c-b+1を取ることがあることの証明
        # 互いに素なので、bを引いてdを足すのを繰り返すと、mod bでc+1と合同になるときが存在する。（逆元を考えれば良い）
        # このとき、購入後がc+1+b*n(n>=0) だったら、cより真に大きいので補充されない。購入だけが続く。
        # したがって、(c+1+b → 購入 →) c+1 → 購入 → c-b+1 → 補充 → c-b+1+d という動きになるときがある。
        # (2) c-b以下を取ることがないことの証明
        # 1回以上、c以上の値を取ったあとは、購入・補充（-b+dで真に増える）か購入(-b)かのどちらか。
        # 後者が発生したときは購入後の値はc+1以上でなければならない。したがって開店時の値は常にc+1以上である。
        # 購入後の値もc-b+1以上である。
        # 以上で証明完。最初からc以下の場合が曲者だが、初日に無いパターンは除外されているので、
        # 初日を乗り切れば増加してc以上の値を取るところまで行ける。すなわち上と同じ話に帰着できる。

        if math.gcd(b, d) == 1:
            if c-b+1 >= 0:
                print('Yes')
                continue
            else:
                print('No')
                continue
        else:
            # 互いに素でない場合。
            # aからgcd(b, d)ずつ引いた数列のうち、c+1以上で最小の要素が 開店時の値の中で取りうる最小値である。
            # 証明はしてないけど上とほとんど同様でしょう。
            g = math.gcd(b, d)
            diff = a - (c+1)
            subtract_width = diff // g * g
            if a - subtract_width >= b:
                print('Yes')
                continue
            else:
                print('No')
                continue

Submission status: Accepted

Solution code:
def solve(P):
    A, B, C, D = P
    if A<B or D<B:
        return False
    if C >= B-1:
        return True
    g = gcd(B,D)
    return A%B+(B-A%B-1)//g*g <= C

from math import gcd

T = int(input())
for _ in range(T):
    P = map(int, input().split())
    print("Yes" if solve(P) else "No")

Submission status: Accepted

Solution code:
def solve(P):
    A, B, C, D = P
    if A<B or D<B:
        return False
    if C >= B-1:
        return True
    g = gcd(B,D)
    return A%g + ((B-A%g-1)//g)*g <= C

from math import gcd

T = int(input())
for _ in range(T):
    P = map(int, input().split())
    print("Yes" if solve(P) else "No")

Submission status: Accepted

Solution code:
def solve(P):
    A, B, C, D = P
    if A<B or D<B:
        return False
    if C >= B-1:
        return True
    g = gcd(B,D)
    return B + A%g - g <= C

from math import gcd

T = int(input())
for _ in range(T):
    P = map(int, input().split())
    print("Yes" if solve(P) else "No")

Submission status: Accepted

Solution code:
from math import gcd

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

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

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

Submission status: Accepted

Solution code:
import math
for _ in range(int(input())):
    a,b,c,d = map(int,input().split())
    print('Yes' if b <= min(a, d, c+1+(a-c-1)%math.gcd(b,d)) else 'No')

Submission status: Accepted

Solution code:
from math import gcd

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

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

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

Submission status: Accepted

Solution code:
def main(a,b,c,d):
  if a<b:return 'No'
  if d<b:return 'No'
  if b<=c+1:return 'Yes'
  if d%b==0:
    if a%b<=c:return 'Yes'
    return 'No'
  # 任意のiで(a+i*d)%b<=cを満たせばOK
  import math
  g=math.gcd(d%b,b)
  e0=a%d
  if g*((b-1-e0)//g)+e0<=c:return 'Yes'
  return 'No'


t=int(input())
abcd=[list(map(int,input().split())) for _ in range(t)]
for a,b,c,d in abcd:
  print(main(a,b,c,d))

Submission status: Accepted

Solution code:
# 【考察】
# 場合分けして考える。
# ★補充の機会無く尽きるケース
#   A < B or A % B > C だと補充されることなく在庫が尽きる。
# ★補充の機会が1回はあるケース（A >= B and A % B <= C ）
#   D < B だとどこかで在庫が尽きる。
#   D == B なら、補充＆購入でプラスマイナスゼロで釣り合う状態が続くので、買い続けられる。
#   D > Bのケースが問題。
#     補充されて補充ゾーンから抜け出しても、その後に補充の機会無く在庫が尽きることが起きうる。
#    「 初期のジュースの本数が X = A + N * D 本の時、補充の機会無く在庫が尽きるような正整数 N があるか？」
#     → 尽きるのは「X % B > C」のケース。
#        大前提として、B <= C + 1 だとこうなることはあり得ないので B > C + 1 で考える。
#        N を増やしていくと、 A % B、(A + D) % B、(A + 2 * D) % B、…と「D % B」ずつ増えていく。
#        こうして C + 1 ～ B - 1 の数が作れると、将来的に在庫が尽きることになる。
#        作れる数は(A + gcd(D, B)の倍数) % Bに限られる。
#        なので、B未満の最大の「A % B + gcd(D, B)の倍数」を求めて、それが　C + 1 ～ B - 1　内にあれば在庫が尽きる。
#        そうでなければ在庫は尽きない。
import math


def solve(A, B, C, D):
    if A < B or A % B > C:
        return 'No'
    if D < B:
        return 'No'
    if D == B:
        return 'Yes'
    # A >= B and A % B <= C and D > B
    if B <= C + 1:
        return 'Yes'
    g = math.gcd(B, D)
    n = (B - 1 - (A % B)) // g
    s = A % B + n * g
    if C + 1 <= s <= B - 1:
        return 'No'
    return 'Yes'


def main():
    T = int(input())
    ans = list()
    for _ in range(T):
        A, B, C, D = map(int, input().split())
        ans.append(solve(A, B, C, D))
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd

t = int(input())
queries = [tuple(int(x) for x in input().split()) for _ in range(t)]
for a, b, c, d in queries:
    if a < b:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if b - c <= 1:
        print("Yes")
        continue

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

Submission status: Accepted

Solution code:
from math import gcd

t = int(input())
queries = [tuple(int(x) for x in input().split()) for _ in range(t)]
for a, b, c, d in queries:
    if a < b:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if b - c <= 1:
        print("Yes")
        continue

    g = gcd(-b, d)
    if g == 1 or b - c > g:
        print("No")
    else:
        m = a - ((a - c) // g) * g
        if c < m < b:
            print("No")
        else:
            print("Yes")

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from math import gcd

    def judge(a, b, c, d):
        if a - b < 0:
            return False
        else:
            if d - b < 0:
                return False

            first = a - b

            l = c + 1
            r = b - 1
            x = gcd(b, d)

            mod_min = first + (first - l + x - 1) // x * x
            mod_max = first + (r - first) // x * x
            if l <= mod_min <= r or l <= mod_max <= r:
                return False
            else:
                return True

    T = int(readline())

    for _ in range(T):
        a, b, c, d = map(int, readline().split())
        print("Yes") if judge(a, b, c, d) else print("No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math
import decimal

ctx = decimal.Context(prec=1, rounding=decimal.ROUND_CEILING)

for i 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)
    r = a % g
    # FYI: https://stackoverflow.com/questions/2795946/getting-ceil-of-decimal-in-python
    #_max = (int(((decimal.Decimal(b, context=ctx) - decimal.Decimal(r, context=ctx)) / decimal.Decimal(g, context=ctx)).to_integral_exact(context=ctx)) * g) + r - g

    # math.ceilは精度不足?でエラーになる: https://cocoinit23.com/math-floor-ceil-error/
    #_max = int(math.ceil((b - r) / g)) * g) + r - g
    #_max = ((math.ceil((b - r) / g)) * g) + r - g

    # OK: (a + b - 1) // b: https://nariagari-igakusei.com/cpp-division-round-up/
    _max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math
import decimal

ctx = decimal.Context(prec=1, rounding=decimal.ROUND_CEILING)

for i 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)
    r = a % g
    # FYI: https://stackoverflow.com/questions/2795946/getting-ceil-of-decimal-in-python
    _max = (int(((decimal.Decimal(b, context=ctx) - decimal.Decimal(r, context=ctx)) / decimal.Decimal(g, context=ctx)).to_integral_exact(context=ctx)) * g) + r - g

    # math.ceilは精度不足でエラーになる: https://cocoinit23.com/math-floor-ceil-error/
    #_max = ((math.ceil((b - r) / g)) * g) + r - g

    # OK: (a + b - 1) // b: https://nariagari-igakusei.com/cpp-division-round-up/
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math
import decimal

ctx = decimal.Context(prec=3, rounding=decimal.ROUND_CEILING)

for i 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)
    r = a % g
    # FYI: https://stackoverflow.com/questions/2795946/getting-ceil-of-decimal-in-python
    _max = (int(((decimal.Decimal(b, context=ctx) - decimal.Decimal(r, context=ctx)) / decimal.Decimal(g, context=ctx)).to_integral_exact(context=ctx)) * g) + r - g

    # math.ceilは精度不足でエラーになる: https://cocoinit23.com/math-floor-ceil-error/
    #_max = ((math.ceil((b - r) / g)) * g) + r - g

    # OK: (a + b - 1) // b: https://nariagari-igakusei.com/cpp-division-round-up/
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math
import decimal

ctx = decimal.Context(prec=5, rounding=decimal.ROUND_CEILING)

for i 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)
    r = a % g
    # FYI: https://stackoverflow.com/questions/2795946/getting-ceil-of-decimal-in-python
    _max = (int(((decimal.Decimal(b, context=ctx) - decimal.Decimal(r, context=ctx)) / decimal.Decimal(g, context=ctx)).to_integral_exact(context=ctx)) * g) + r - g

    # math.ceilは精度不足でエラーになる: https://cocoinit23.com/math-floor-ceil-error/
    #_max = ((math.ceil((b - r) / g)) * g) + r - g

    # OK: (a + b - 1) // b: https://nariagari-igakusei.com/cpp-division-round-up/
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math
import decimal

ctx = decimal.Context(prec=100, rounding=decimal.ROUND_CEILING)

for i 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)
    r = a % g
    _max = (int(((decimal.Decimal(b, context=ctx) - decimal.Decimal(r, context=ctx)) / decimal.Decimal(g, context=ctx)).to_integral_exact(context=ctx)) * g) + r - g
    #_max = ((math.ceil((b - r) / g)) * g) + r - g
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

for i 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)
    r = a % g
    #_max = int(math.ceil((b - r) / g) - 1) * g + r
    _max = b + r - g
    #_max = ((math.ceil((b - r) / g)) * g) + r - g
    #_max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import math

for i 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)
    r = a % g
    #_max = (math.ceil((b - r) / g) - 1) * g + r
    _max = ((b - r + g - 1)//g) * g + r - g
    if c < _max:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import math

t=int(input()) 
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")
    elif b-math.gcd(b,d)+(a%math.gcd(b,d))>c:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
import math
N = int(input())
for i in range(N):
  A,B,C,D = map(int,input().split())
  if A<B: #初期の在庫が足りないならダメ
    print("No")
    continue
  if B>D: #消費のほうが大きいならダメ。
    print("No")
    continue
  if A%B > C: #一回目の補給が間に合うか。
    print("No")
    continue
  cycle = D-B
  GCD = math.gcd(B,cycle)
  #print(GCD)
  if GCD == 1 and B-1 > C:
    print("No")
    continue
  if B-GCD > C:
    print("No")
    continue
  print("Yes")

Submission status: Accepted

Solution code:
import math
t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if a < b or b > d:  # 1手目から不可能、りんごが単調減少
        print("No")
        continue

    # ダメな場合とは　➡　bより小さいのに補充しない
    # (aから始まり、dを足していく) mod b > c
    # となる場合があったら無理
    g = math.gcd(b, d)
    max_rem = b - g + a % g
    if max_rem > c:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
from math import gcd

t = int(input())
for _ in range(t):
    a, b, c, d = map(int, input().split())
    if b > d or b > a:
        print("No")
    else:
        tmp = gcd(b, d)
        rem = a % tmp
        min_c = (c - rem) // tmp
        if min_c + 1 >= b // tmp:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

Solution code:
from math import gcd
def solve():
  T = int(input())
  ans = ['No']*T
  for i in range(T):
    A,B,C,D = map(int, input().split())
    if A<B:
      continue
    now = A-(-(-(A-C)//B))*B
    if now<0:
      continue
    if D<B:
      continue
    if D%B==0:
      ans[i] = 'Yes'
      continue
    if C>=B:
      ans[i] = 'Yes'
      continue
    if B-gcd(D%B,B)>C:
      continue
    ans[i] = 'Yes'
  return ans
print(*solve(),sep='\n')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

for i in range(t):
    a,b,c,d=abcd[i]
    if a<b:
        print("No")
    elif d<b:
        print("No")
    elif c>=b:
        print("Yes")
    elif b-math.gcd(b,d)+(a%math.gcd(b,d))>c:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
import math
t=int(input())
for i 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=math.gcd(b,d);print("Yes"if c>=a%g+b-g else"No")

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

def sub(a,b,c,d):
    x1 = a - max(0, (a - (c+1))//b) * b
    if d<b:
        ans = "No"
    elif a<b:
        ans = "No"
    elif d%b==0:
        if x1>=b:
            ans = "Yes"
        else:
            ans = "No"
    else:
        k = gcd(d,b)
        x2 = x1 - (x1 - (c+1))//k * k
        if x2>=b:
            ans = "Yes"
        else:
            ans = "No"
    return ans

t = int(input())
ans = []
for i in range(t):
    a,b,c,d = map(int, input().split())
    ans.append(sub(a,b,c,d))
write("\n".join(ans))

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

def sub(a,b,c,d):
    x1 = a - (a - (c+1))//b * b
    if d<b:
        ans = "No"
    elif a<b:
        ans = "No"
    elif d%b==0:
        if x1>=b:
            ans = "Yes"
        else:
            ans = "No"
    else:
        k = gcd(d,b)
        x2 = x1 - (x1 - (c+1))//k * k
        if x2>=b:
            ans = "Yes"
        else:
            ans = "No"
    return ans

t = int(input())
ans = []
for i in range(t):
    a,b,c,d = map(int, input().split())
    ans.append(sub(a,b,c,d))
write("\n".join(ans))

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 b > a or b > d:
        flg = False
    else:
        if b - 1 <= c:
            flg = True
        elif a % b > c:
            flg = False
        else:
            g = gcd(d, b)
            if (b - 1 - a % b) // g * g + a % b <= c: 
                flg = True
            else:
                flg = False

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