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:
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import sys
from fractions import gcd

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

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


def main():
    T = rl(int)
    for t in xrange(1, T+1):
        A, B, C, D = srl(int)
        print "Yes" if solve(A, B, C, D) else "No"

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for _ in range(T):
    A, B, C, D = map(int, input().split())
    #print("----", _, A, B, C, D)
    if A < B:
        print("No")
        continue
    
    if C < A%B < B:
        print("No")
        continue
    
    if D % B == 0:
        print("Yes")
        continue
    
    if D < B:
        print("No")
        continue
    
    if C+(gcd(B,D)) < B:
        print("No")
        continue
    
    print("Yes")

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import fractions

def isok(a,b,c,d):
    if a < b or b > d:
        print('No')
        return
    g= fractions.gcd(d, b)
    r=((c-a%g)//g)*g+a%g
#    print(r)
    if r+g-b < 0:
        print('No')
    else:
        print('Yes')
    

T=int(input())

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

Submission status: Accepted

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

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
        g = fractions.gcd(b,d)
        f = (b -a) // g
        if (b - a) % g == 0:
            f -= 1
        if g == 0 or c >= a + f * g:
            print("Yes")
            return
        print("No")
        return

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

Submission status: Accepted

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

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

  cnt=gcd(b,d)
  mi=a-b
  ma=a-c
  if ma-mi > cnt :
    return True
  elif ma-mi <= 1:
    return False
  elif (mi+cnt)//cnt*cnt < ma:
    return True
  else:
    return False

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(100000)

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

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

    if a < b:
        print("No")
        continue

    if b > d:
        print("No")
        continue

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

    diff = d % b
    if diff == 0:
        if a % b <= c:
            print("Yes")
            continue
        else:
            print("No")
            continue

    g = gcd(b, diff)

    init_mod = c % b

    base_mod = init_mod % g
    if b + base_mod - g > c:
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
from fractions import gcd

T = int(input())
qs = [tuple(map(int,input().split())) for i in range(T)]

def solve(q):
    a,b,c,d = q
    if b > d: return False
    if a < b: return False
    a %= b
    if a > c: return False
    if b == d: return True
    g = gcd(b, d)
    return b-g <= c

for q in qs:
    print('Yes' if solve(q) else 'No')

Submission status: Accepted

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def gcd(a, b):
    """greatest common divisor"""
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def solve(f):
    t = f.read_int()
    ans = []

    def solve2():
        a, b, c, d = f.read_int_list()

        g1 = gcd(gcd(a, b), d)

        if d < b: return 'No'
        if a < b: return 'No'
        if b <= c+g1: return 'Yes'
        g2 = gcd(b, d)

        lo = ((c+1)-a)%g2
        if lo == 0 or lo + (b-c-1) >= g2: return 'No'

        return 'Yes'

    for _ in xrange(t):
        ans.append(solve2())

    return "\n".join(ans)


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)

Submission status: Accepted

Solution code:
import fractions

def main():
	t = int(input())
	qs = [list(map(int, input().split())) for _ in range(t)]
	for q in qs:
		sub(q)

def sub(q):
	a, b, c, d = q
	if d - b < 0:
		print("No")
		return
	
	if a - b < 0:
		print("No")
		return

	if b > c:
		gcd_bd = fractions.gcd(d, b)
		i = - 10
		while True:
			if 0 < gcd_bd * i + (a - c) % gcd_bd < b - c:
				print("No")
				return
			elif gcd_bd * i + (a - c) % gcd_bd >= b - c:
				print("Yes")
				return
			i += 1
				
	print("Yes")
	return
	
if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import fractions


def solve(a, b, c, d):
    if a < b or d < b:
        return False
    if b <= c + 1:
        return True
    gcd_bd = fractions.gcd(b, d)
    cc = c - a % gcd_bd
    b //= gcd_bd
    cc //= gcd_bd
    if b <= cc + 1:
        return True
    return False


t = int(input())
buf = []
for _ in range(t):
    a, b, c, d = map(int, input().split())
    buf.append('Yes' if solve(a, b, c, d) else 'No')
print('\n'.join(map(str, buf)))

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a,b = b,a
    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')
    else:
        g = gcd(B,D)
        k = B//g
        r = (A-C)%B
        if r == 0:
            sm = C
        else:
            sm = C+r-B
        if sm < 0:
            print('No')
        else:
            s = sm%g
            if s + (k-1)*g <= C:
                print('Yes')
            else:
                print('No')

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from fractions import gcd

def solve(A,B,C,D):
  if D<B:
    return "No"
  if A<B:
    return "No"
  if C>=B-1:
    return "Yes"
  g = gcd(B,D)
  if A-(A-C-1)/g*g<B:
    return "No"
  return "Yes"

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

Submission status: Accepted

Solution code:

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


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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

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:
    print("  V1", file=stderr)
    return False
  CC = C + 1
  if B <= CC:
    print("  V2", file=stderr)
    return True
  g = gcd(D, B)
  # [CC, B) is prohobited
  if CC <= B - g:
    print("  V3", file=stderr)
    return False
  else:
    print("  V4", file=stderr)
    return A % g < CC % g

T = read()
for _ in range(T):
  A, B, C, D = reads()
  print("Yes" if solve(A, B, C, D) else "No")

Submission status: Accepted

Solution code:
T = int(input())
def gcd(a,b):
	if a < b:
		a,b = b,a
	while b > 0:
		c = a % b
		a = b
		b = c
	return a

YES = 'Yes'
NO = 'No'
for i in range(T):
	A,B,C,D = map(int,input().split())
	if D < B or A < B:
		print(NO)
		continue
	D = D % B
	if C >= B:
		print(YES)
		continue
	rest = A % B
	if rest > C:
		print(NO)
		continue
	if D == 0:
		print(YES)
		continue
	g = gcd(B,D)
	left = C - rest
	right = B - rest
	n = left // g + 1
	if n * g < right:
		print(NO)
	else:
		print(YES)

Submission status: Accepted

Solution code:
from fractions import gcd

def solve():
    a, b, c, d = map(int, input().split(' '))
    if a < b or d < b: return False
    if c >= b: return True
    
    a = a % b
    d = d % b
    x = gcd(b, d)
    k = (b - a) // x
    if (b - a) % x == 0: k -= 1
    return not (c < a + k * x < b)
    
def main():
    t = int(input())
    ans = []
    for _ in range(t):
        ans.append(['No','Yes'][solve()])
    for a in ans:
        print(a)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D:
        print('No')
    elif A < B:
        print('No')
    elif C + 1 >= B:
        print('Yes')
    else:
        q = gcd(B,D)
        r = (A-C)%q
        if r == 0:
            r = q
        if C + r >= B:
            print('Yes')
        else:
            print('No')

Submission status: Accepted

Solution code:
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

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


T = int(input())

for turn in range(1, T+1):
    init, sell, base, add = map(int, input().split())

    hoge = gcd(sell, add)

    ans = "Yes"
    if init < sell or sell > add:
        ans = "No"
    elif base+hoge >= sell:
        if init % sell > base:
            ans = "No"
    else:
        ans = "No"

    print(ans)

Submission status: Accepted

Solution code:
# B
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
T = int(input())
res_list = []

for _ in range(T):
    A, B, C, D = map(int, input().split())
    E = gcd(B, D)
    res = "Yes"
    if A < B:
        res = "No"
    if D < B:
        res = "No"
    if C < B - E:
        res = "No"
    F = A - ((A - C - 1) // B) * B - B
    if F < 0:
        res = "No"
    res_list.append(res)
for i in range(T):
    print(res_list[i])

Submission status: Accepted

Solution code:
# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

T = int(input())
for _ in range(T):
    A, B, C, D = map(int, input().split())
    if D < B or A < B:
        print("No")
    else:
        g = egcd(B, D)[0]
        mA = A % g
        mC = C % g
        k = C + (mA - mC if mA - mC > 0 else mA - mC + g)
        k -= B
        if k >= 0:
            print("Yes")
        else:
            print("No")

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import fractions as math


def read_ints():
    return [int(c) for c in input().split()]


def solve(a, b, c, d):
    if a < b:
        return False
    if d < b:
        return False
    if c >= b:
        return True
    e = a % b
    delta = d % b
    if delta == 0:
        return e <= c
    g = math.gcd(b, delta)
    maxv = b - g
    return maxv <= c


def main():
    n = int(input())
    for _ in range(n):
        print("Yes" if solve(*read_ints()) else "No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
t = int(raw_input())
for _ in xrange(t):
    a, b, c, d = map(int, raw_input().split())
    if a < b or b > d:
        print 'No'
        continue
    a -= b
    if a > c:
        a -= (a - c + b - 1) / b * b
    if a < 0:
        print 'No'
    elif d % b == 0 or c >= b:
        print 'Yes'
    else:
        d = gcd(b, d)
        a += (c - a + d) / d * d
        print 'No' if a < b else 'Yes'

Submission status: Accepted

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

t=int(input())
result=[]
for i in range(t):
    a,b,c,d=list(map(int,input().split()))
    if b>d:
        result.append('No')
    elif a<b:
        result.append('No')
    elif a%b>c:
        result.append('No')
    elif b-c-1<gcd(b,d):
        result.append('Yes')
    else:
        result.append('No')

for r in result:
    print(r)

Submission status: Accepted

Solution code:
T = int(input())
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n
def check(a, b, c, d):
    if b > a or d < b:
        return 0
    g = gcd(b, d)
    k = (a - c - 1) // g
    p = a - k*g
    if p - b < 0:
        return 0
    return 1

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

Submission status: Accepted

Solution code:


import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

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

def good(a,b,c,d):
    # easy cases
    if b>a: return 0
    if b>d: return 0
    if b<=c: return 1
    # normal case
    # think about the number of cans mod b
    # this shouldn't be in the interval (c,b)
    a%=b
    d%=b
    g=gcd(b,d)
    a+=((b-a-1)//g)*g
    return not c<a<b

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

Submission status: Runtime Error

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


import math
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 = math.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: Runtime Error

Solution code:
from fractions import gcd
t = int(input())
ans = ['Yes']*t
for i in range(t):
    a,b,c,d = map(int,input().split())
    if d < b:
        ans[i] = 'No'
    elif a < b:
        ans[i] = 'No'
    elif d == b:
        if c < a%b < b:
            ans[i] = 'No'
    else:
        if (1+(c-a%b)//(d%b))*(d%b) < b-a%b:
            ans[i] = 'No'
print("\n".join(ans))

Submission status: Runtime Error

Solution code:
from math 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: Runtime Error

Solution code:
t = int(input())
for _ in range(t):
  a, b, c, d = map(int, input().split())
  zaiko = a
  rereki = [False] * 10 ** 20
  rereki[zaiko] = True
  while True:
    zaiko -= b
    if zaiko < 0:
      ans = 'No'
      break
    if zaiko <= c:
      zaiko += d
    if rereki[zaiko]:
      ans = 'Yes'
      break
    rereki[zaiko] = True
  print(ans)

Submission status: Runtime Error

Solution code:
t = int(input())
for _ in range(t):
  a, b, c, d = map(int, input().split())
  zaiko = a
  rereki = [False] * 10 ** 20
  while True:
    zaiko -= b
    if zaiko < 0:
      ans = 'No'
      break
    if zaiko <= c:
      zaiko += d
    if rereki[zaiko]:
      ans = 'Yes'
      break
    rereki[zaiko] = True
  print(ans)

Submission status: Runtime Error

Solution code:
t = int(input())
for _ in range(t):
  a, b, c, d = map(int, input().split())
  zaiko = a
  rereki = [False] * 10 ** 13
  while True:
    zaiko -= b
    if zaiko < 0:
      ans = 'No'
      break
    if zaiko <= c:
      zaiko += d
    if rereki[zaiko]:
      ans = 'Yes'
      break
    rereki[zaiko] = True
  print(ans)

Submission status: Runtime Error

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

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

import math

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 = math.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: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import gcd

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

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: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    

    ll t;cin>>t;
    while(t--){
        ll a,b,c,d;cin>>a>>b>>c>>d;
        ll rem=a;
        while(true){
            if(rem/b==0){
                cout<<"No"<<endl;
                break;
            }
            rem%=b;
            if(rem<=c) rem+=d;
            if(rem==a){
                cout<<"Yes"<<endl;
                break;
            }
        }
    }
    return 0;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]
#わからんから解説見た。解説見たけどgcdの下りが自分で導出できんかったのでとりあえ
ずバカループでなんとかしてみた。これで通るかな。
def fFunc(iA,iB,iC,iD):
    if iA < iB or iD < iB:
        return False
    if iC >= iB :
        return True
    iJ = iA % iB
    iK = iD % iB
    i = 1
    while True:
        j = iJ + i * iK
        if iB <= j:
            return True
        else:
            if iC < j:
                return False
        if iK == 0:
            return True
        i += 1
    return True

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

Submission status: Runtime Error

Solution code:
import sys

iT = int(input())
aR = [[int(x) for x in sLine.split()] for sLine in sys.stdin.readlines()]
#わからんから解説見た。解説見たけどgcdの下りが自分で導出できんかったのでとりあえ
ずバカループでなんとかしてみた。これで通るかな。
def f調1(iA,iB,iC,iD):
    if iA < iB or iD < iB:
        return False
    if iC >= iB :
        return True
    iJ = iA % iB
    iK = iD % iB
    i = 1
    while True:
        j = iJ + i * iK
        if iB <= j:
            return True
        else:
            if iC < j:
                return False
        if iK == 0:
            return True
        i += 1
    return True

for eR in aR:
    if f調1(*eR) :
        print("Yes")
    else:
        print("No")

Submission status: Runtime Error

Solution code:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-


def solve(x):
    x1 = x[0]
    x2 = x[1]
    x3 = x[2]
    x4 = x[3]

    x11 = x1 % x2
    x41 = x4 % x2

    if x1 < x2:
        return False

    if x1 == x2:
        if x4 < x2:
            return False
        else:
            return True

    if x4 < x2:
        return False
    
    while True:
        a = x11 + x41
        if a == x11:
            if x11 <= x3:
                return True
            else:
                return False
        if a > x3 and a < x2:
            return False
        if a < x3 and a > x2:  
            return False
        if a >= x3 and a >= x2:
            return True
        x11 = a

num = int(input())

s = []
for i in xrange(num):
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    q = [a, b, c, d]
    s.append(q)

for i in s:
    if solve(i):
        print "Yes"
    else:
        print "No"

Submission status: Runtime Error

Solution code:
#!/usr/local/bin/python
# -*- coding: utf-8 -*-


def solve(x):
    x1 = x[0]
    x2 = x[1]
    x3 = x[2]
    x4 = x[3]

    x11 = x1 % x2
    x41 = x4 % x2

    if x1 < x2:
        return False

    if x1 == x2:
        if x4 < x2:
            return False
        else:
            return True

    if x4 < x2:
        return False
    
    while True:
        a = x11 + x41
        if a == x11:
            if x11 <= x3:
                return True
            else:
                return False
        if a > x3 and a < x2:
            return False
        if a < x3 and a > x2:  
            return False
        if a >= x3 and a >= x2:
            return True
        x11 = a

num = int(input())

s = []
for i in xrange(num):
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    q = [a, b, c, d]
    s.append(q)

for i in s:
    if solve(i):
        print "yes"
    else:
        print "no"

Submission status: Runtime Error

Solution code:
import sys
import math

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

Submission status: Runtime Error

Solution code:
import math

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

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

Submission status: Runtime Error

Solution code:
import math
T = int(input())
data = []
for i in range(T):
    data.append([int(xi) for xi in input().split()])

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

for a, b, c, d in data:
    print('Yes') if judge(a, b, c, d) else print('No')