Problem:


Score : 600 points

Problem Statement

Ringo Mart, a convenience store, sells apple juice.

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

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

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

Constraints

1 \leq T \leq 300

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

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

Output

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

Sample Input 1

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

Sample Output 1

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

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

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

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

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

and so on, thus Snuke can buy juice indefinitely.

Sample Input 2

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

Sample Output 2

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



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


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

Submission status: Accepted

Solution code:
import fractions
T = int(input())

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

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

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

  gcd=fractions.gcd(d,b)
  e=b-gcd+a%gcd
  if e>c:
    print('No')
  else:
    print('Yes')

Submission status: Accepted

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

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


ans_list = []
for i in range(T):
    A = query[i][0]
    B = query[i][1]
    C = query[i][2]
    D = query[i][3]
    if A < B:
        ans_list.append("No")
        continue
    if B > D:
        ans_list.append("No")
        continue
    if C >= B:
        ans_list.append("Yes")
        continue
    g = gcd(B, D)
    max_modB = B - g + A%g
    if max_modB > C:
        ans_list.append("No")
    else:
        ans_list.append("Yes")
        

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

Submission status: Accepted

Solution code:
import fractions


def run(t, a, b, c, d):
    ret = []
    for i in range(t):
        ret.append(check(a[i], b[i], c[i], d[i]))
    return ret


def check(a, b, c, d):
    if a < b:
        return 'No'
    if d < b:
        return 'No'
    if c < b:
        g = fractions.gcd(b, d)
        amodb = a % b
        if g == 1:
            if b - 1 > c:
                return 'No'
        elif g == b:
            if amodb > c:
                return 'No'
        else:
            if (b - g) > c:
                return 'No'
    return 'Yes'


def read_line():
    t = int(input())
    a = []
    b = []
    c = []
    d = []
    for i in range(t):
        at, bt, ct, dt = list(map(int, input().split()))
        a.append(at)
        b.append(bt)
        c.append(ct)
        d.append(dt)
    return (t, a, b, c, d)


def main():
    t, a, b, c, d = read_line()
    ret = run(t, a, b, c, d)
    for i in range(t):
        print(ret[i])


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())
abcd_list = [[int(i) for i in input().split()] for _ in range(t)]

for i in range(len(abcd_list)):
    a, b, c, d = abcd_list[i]
    if b > a:
        print("No")
        continue
    if b > d:
        print("No")
        continue
    if c > b:
        print('Yes')
        continue
    g = gcd(b, d)
    max_mod_b = b - g + a % g
    if max_mod_b > c:
        print('No')
    else:
        print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 本番中には解けなかった。解説pdfにある3つの場合分けはできた。
# B個の購入を可能なかぎりしたあとの個数が、「Cより大きくBより小さい」値に
# なることがあるとNoになる、ということには気づいたのだが、
# どう解いてよいか混乱して手がつけられなかった
#
#
# 解説pdf https://img.atcoder.jp/agc026/editorial.pdf を見た
#
# B個の購入を行った直後の個数の遷移を、mod Bの世界で考える。
#   最初は A mod B個。
#   B個の購入を可能な限り行った後も A mod B個で変わらず。
#   D個入荷すると    (A + D) mod B個。
# つまり、入荷するたびに、
# A からスタートして (A + D) mod B, (A + 2D) mod B, ... と遷移していく。
# 
# 遷移を無限に繰り返すと、mod Bの世界でのとりうる値は、g = gcd(B, D)として
#   (A % g), g + (A % g), 2g + (A % g), ..., kg + (A % g) (kは、kg + (A % g)がB未満となる最大の整数) のどれかとなる。
# ここでkを直接求めるのは難しい。
# かわりに、mを整数として、mg + (A % g)が最初にB以上となるのを求めるのは簡単で、それは B + (A % g)。
# これよりひとつ分小さいのは、B + (A % g) - gで、これが kg + (A % g)に等しい。
# 
# (A % g) + B - g が、C を超える場合、次に入荷が行われない。次もBを引くと個数が負になってしまうので No。
# (A % g) + B - g が、C 以下の場合、次に入荷が行われる。Yes。
#
#
# 解説PDFの、「また，(B/g − 1) × inv(D/g, B/g) 回 D を足したときにこの上界が達成できます」
# については理解できていない。
#



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys


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


def solve(A, B, C, D):
    if B > A:
        return "No"
    if B > D:
        return "No"
    if B <= C:
        return "Yes"

    g = gcd(B, D)
    if B - g + (A % g) > C:
        return "No"
    else:
        return "Yes"


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

Submission status: Accepted

Solution code:
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
t=i1()
def gcd(a,b):
  while b:
    if a<b:
        c=b
        b=a
        a=c
    if b:a%=b
  return a
for i in range(t):
 [a,b,c,d]=i2()
 if a<b:
   print("No")
 else:
   if d<b:
      print("No")
   else:
      if c>=b:
         print("Yes")
      else:
         g=gcd(b,d)
         x=b-g+a%g
         if x>c:
           print("No")
         else:
           print("Yes")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 解説pdf https://img.atcoder.jp/agc026/editorial.pdf を見た



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys


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



def solve(A, B, C, D):
    if B > A:
        return "No"
    if B > D:
        return "No"
    if B <= C:
        return "Yes"

    g = gcd(B, D)
    if B - g + (A % g) > C:
        return "No"
    else:
        return "Yes"


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

Submission status: Accepted

Solution code:
import fractions
N = int(input())
x = []
for i in range(N):
    a1,b1,c1,d1=[int(i) for i in input().split()]
    x.append([a1,b1,c1,d1])
for i in range(N):
  y = x[i]
  if y[0] < y[1]:
    print("No")
  elif y[1] > y[3]:
    print("No")
  elif y[1] > y[2]:
    ama = y[0] % y[1]
    mo = y[3] %  y[1]
    if mo == 0:
      if ama<= y[2]:
        print("Yes")
      else:
          print("No")
    elif mo <= y[1]-y[2]-1:
      print("No")
    else:
        to = y[1] % mo
        if to == 0:
          if ama<= y[2]:
            print("Yes")
          else:
              print("No")
        else:
          are = fractions.gcd(to, y[1])
          if are-ama%are <= y[1]-y[2]-1:
            print("No")
          else:
            print("Yes")
          
  else:
    print("Yes")

Submission status: Accepted

Solution code:
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
T=int(input())
 
Query=[]
for i in range(T):
  Query.append(list(map(int,input().split())))
 
for i in range(T):
  while(True):
    if Query[i][0]%Query[i][1]>Query[i][2] or Query[i][0]<Query[i][1] or Query[i][1]>Query[i][3]:
      print('No')
      break;
    G=gcd(Query[i][1],Query[i][3]) #この倍数分の増減のみ考えれば良い
    '''
    A,B,C,DがQuery[i]の0,1,2,3に対応
    BmodG,DmodGは0(GはB,Dの約数であるため)よりmodGの世界で個数の増減はない。昼の購入で0個減少。夜の仕入れで0個増加。
    つまり、初期個数をAmodGとすると、個数は一定
    出現する可能性のあるBは買う個数であり、B-Gを考えると、買いきれない個数で出現しうる最大の個数が求まる。
    但し、初期個数を考える必要がある。
    初期個数によってループする幅が一緒でも取りうる値は異なる。
    
    例：
    B=24,C=19,D=36 この時,G=12
    
    A=31の場合 AmodG(本来の個数)
    7(31)→7(7)→7(43)→7(19)→7(31)→...
    A=30の場合 AmodG(本来の個数)
    6(30)→6(6)→6(42)→6(18)→6(30)→...
    
    Bを超えない最大数について、初期個数を考慮すると、B-G+AmodGとなる。
    G>AmodGであるため、この数が購入数Bを超えることはない
    つまり、B-G+AmodG>CならばNo,そうでなければYes
    '''
    if Query[i][1]-G+Query[i][0]%G>Query[i][2]:
      print('No')
      break;
    else:
      print('Yes')
      break;

Submission status: Accepted

Solution code:
from sys import stdin
from fractions import gcd
columns = int(stdin.readline().rstrip())
datas = [stdin.readline().rstrip().split() for _ in range(columns)]
for data in datas:
    A = int(data[0])
    B = int(data[1])
    C = int(data[2])
    D = int(data[3])
    if A < B:
        print("No")
        continue
    if D < B:
        print("No")
        continue
    if C > B:
        print("Yes")
        continue
    g = gcd(B,D)
    if (B - g + A % g) >C :
        print("No")
    else:
        print("Yes")

Submission status: Accepted

Solution code:
from fractions import gcd
T = int(input())
for i in range(T):
    A, B, C, D = map(int, input().split())

    # 初日でケーキが買えない
    if B > A:
        print("No")
        continue

    # 毎日補充できても足りなくなる
    if B > D:
        print("No")
        continue

    # 買切る前に必ず入荷が発生する
    if C >= B:
        print("Yes")
        continue
        
    if B - gcd(B, D) + (A % gcd(B, D)) <= C:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
from fractions import gcd
t=int(input())
for i in range(t):
	a,b,c,d=map(int,input().split())
	if a<b or 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:

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


def judge(a,b,c,d):
    if a<b or d<b:
        return False
    elif c >= b:
        return True
    else:
        g = findGCD(b,d)
        thr = b-g+a%g
        if thr > c:
            return False
        else:
            return True
        
T = int(input())
ABCD = []
for i in range(T):
    ABCD.append(list(map(int, input().split())))
        
for a,b,c,d in ABCD:
    if judge(a,b,c,d):
        print("Yes")
    else:
        print("No")

Submission status: Accepted

Solution code:
def gcd(x,y):
    if x < y:
        tmp = y
        y = x
        x = tmp

    while x % y != 0:
        r = x % y
        x = y
        y = r
    return y

n = int(input())
x = []
for i in range(n):
    a,b,c,d = map(int,input().split())
    x.append((a,b,c,d))

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

for i in range(n):
    a,b,c,d = x[i][0],x[i][1],x[i][2],x[i][3]
    f(a,b,c,d)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from math import ceil

def gcd(a, b):
    assert a > 0 and b > 0
    while b > 0:
        r = a % b
        a = b
        b = r
    return a

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
h=[]
for i in range(n):
    w=list(map(int,input().split()))
    h.append(w)
for i in range(n):
    a,b,c,d=h[i][0],h[i][1],h[i][2],h[i][3]
    if(b>a or b>d):
        print("No")
        continue
    if(b<=c):
        print("Yes")
        continue
    if(b-gcd(b,d)+a%gcd(b,d)<=c):print("Yes")
    else:print("No")
    continue

Submission status: Accepted

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

T=int(input())
Juice=[None]*T
for i in range(T):
    Juice[i]=list(map(int,input().split()))

#A最初の在庫,Bすぬけ君が買う本数,C以下の場合D追加


#A→A%B
def juicecheck(i):
    A=Juice[i][0]
    B=Juice[i][1]
    C=Juice[i][2]
    D=Juice[i][3]

    if A<B:
        print("No")
        return
    elif B>D:
        print("No")
        return
    elif B-1<=C:
        print("Yes")
        return
    else:
        x=A%B
        y=D%B
        

        z=gcd(B,D)

        if z==1 or B-(C+1)>=z or  (C+1)%z<=x%z<=(B-1)%z or ( (C+1)%z>B%z and ((C+1)%z<=x%z or x%z<B%z) ):
            print("No")
            return

        print("Yes")
        return
                
        #(x+n*y)%B==[C+1,B)となるnがあれば"No"

for i in range(T):
    juicecheck(i)

Submission status: Accepted

Solution code:
from fractions import gcd

t = int(input())
a = []
d = 0
for i in range(t):
  a.append(list(map(int,input().split())))
for j in a:
  if j[0] < j[1] or j[1] > j[3]:
    print("No")
  else:
    b = j[0] % j[1]
    k = gcd(j[1],j[3])
    c = j[0] % k
    d = j[2] % k
    if c > d:
      e = j[2] + c - d
    else:
      e = j[2] + k + c - d

    if j[1] > e:
      print("No")
    else:
      print("Yes")

Submission status: Accepted

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

t = int(input())
a = []
d = 0
for i in range(t):
  a.append(list(map(int,input().split())))
for j in a:
  if j[0] < j[1] or j[1] > j[3]:
    print("No")
  else:
    b = j[0] % j[1]
    k = gcd(j[1],j[3])
    c = j[0] % k
    d = j[2] % k
    if c > d:
      e = j[2] + c - d
    else:
      e = j[2] + k + c - d

    if j[1] > e:
      print("No")
    else:
      print("Yes")

Submission status: Accepted

Solution code:
from fractions import gcd
t = int(input())

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

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

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

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

Submission status: Accepted

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


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


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

    if D < B:
        return 'No'

    if C >= B:
        return 'Yes'

    g = gcd(B, D)
    if B - g + (A % g) > C:
        return 'No'

    return 'Yes'


@mt
def slv(T, Q):
    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: Accepted

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

def solve():
    a, b, c, d = map(int, input().split())
    if d < b:return "No"
    if a < b:return "No"
    if c >= b:return "Yes"
    g = gcd(d, b)
    a %= b
    if((c-a) // g != (b-a-1) // g):return "No"
    else: return "Yes"


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

Submission status: Accepted

Solution code:
T = int(input())

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

def solve(A, B, C, D):
    if A < B:
        return False
    if D < B:
        return False
    if C >= B:
        return True
    s = A % B
    d = D % B
    n = B - C
    if d == 0:
        return s <= C
    else:
        g = gcd(d, B)
        n = (B - 1 - s) // g
        m = s + n * g
        return m <= C

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

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

Submission status: Accepted

Solution code:
def gcd(X,Y):
  if X < Y:
    tmp = X
    X = Y
    Y = tmp
  if Y == 0:
    return 0
  while X % Y != 0:
    r = X % Y
    X = Y
    Y = r
  return Y
T = int(raw_input())
Q = [map(int, raw_input().split()) for _ in range(T)]
for q in Q:
  A,B,C,D = q
  if B > A:
    print 'No'
  elif B > D:
    print 'No'
  elif B <= C:
    print 'Yes'
  else:
    A = A%B
    D = D%B
    g = gcd(B,D)
    maximum = A if g == 0 else B-g+A%g
    if maximum > C:
      print 'No'
    else:
      print 'Yes'

Submission status: Accepted

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

class query:
    def __init__(self, a, b, c, d):
        self.a = a
        self.b = b
        self.c = c
        self.d = d
    def isEternal(self):
        if self.a < self.b:
            return "No"
        if self.d < self.b:
            return "No"
        if self.b <= self.c:
            return "Yes"
        g = gcd(self.d, self.b)
        if self.b - g + self.a % g > self.c:
            return "No"
        return "Yes"

if __name__ == "__main__":
    t = int(input())
    querys = [query(*[int(s) for s in input().split()]) for _ in range(t)]
    for q in querys:
        print(q.isEternal())

Submission status: Accepted

Solution code:
import fractions
T = int(input())
for i in range(T):
  A, B, C, D = map(int, input().split())
  if (A < B):
    print('No')
  elif (B > D):
    print('No')
  elif (C >= B):
    print('Yes')
  elif (A % B > C):
    print('No')
  elif (D % B == 0):
    print('Yes')
  else:
    gcdBD = fractions.gcd(B, D)
    if (C + gcdBD >= B):
      print('Yes')
    else:
      print('No')

Submission status: Accepted

Solution code:



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

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

def aprime(a,b,c,d):
    app = a%b
    return(c+d-b - (c-app)%(d-b))


def ans(a,b,c,d):
    if d < b or a<b or (a%b > c and c<b):
        return('No')
    elif b == d or c > b:
        return('Yes')
    elif aprime(a,b,c,d) < b:
        return('No')
    else: return (ans2(aprime(a,b,c,d),b,c,d))

def ans2(a,b,c,d):
    b2 = b % (d-b)
    gcdbbd = abs(computeGCD(b2,b-d))
    aa = a - ((a-c)//gcdbbd)*gcdbbd
    if aa == c: aa = c+ gcdbbd
    if aa >= b: return('Yes')
    else: return('No')

for q in qs:
    print (ans(*q))

Submission status: Accepted

Solution code:
#
import sys

n = int(input())
a=[]
b=[]
c=[]
d=[]
for j in range(0,n):
    t1,t2,t3,t4 = (int(i) for i in input().split())  
    a.append(t1)
    b.append(t2)
    c.append(t3)
    d.append(t4)
    
for i in range(0,n):
    if a[i] < b[i]:
        print("No")
    elif d[i] < b[i]:
        print("No")
    else:
        p= b[i]
        q= d[i]
        while p%q :
            r=q
            q=p%q
            p=r
        if (b[i]-q)+a[i]%q > c[i]:
            print("No")
        else:
            print("Yes")

Submission status: Accepted

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


T = int(input())
a = []
for i in range(T):
    a.append(list(map(int, input().split())))
for r in a:
    s, b, c, d = r[0], r[1], r[2], r[3]
    mod_list = []
    if (s < b) or (b>d):
        print('No')
        continue
    if (c>b):
        print('Yes')
        continue

    g = gcd(b,d)

    if b- g + s%g > c:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
import fractions
T = int(input())

L = []
for i in range(0,T):
    L = list(map(int, input().split()))
    A = L[0]
    B = L[1]
    C = L[2]
    D = L[3]

    ans = "Yes"
    if A < B: #前提条件
        ans = "No"
    elif D < B: #前提条件
        ans = "No"
    elif B - C <= 1: #BとCの差が1より小さければ何が来てもOK
        ans = "Yes"
    elif C < B-fractions.gcd(B,D)+(A%fractions.gcd(B,D)):
        ans = "No"


    print(ans)
    L = []

Submission status: Accepted

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

for a,b,c,d in ABCD:
    if a < b:
        print('No')
        continue
    if d < b:
        print('No')
        continue
    tmp = a % b
    if tmp > c:
        print('No')
        continue
    if d % b == 0:
        print('Yes')
        continue
    if c >= b-1:
        print('Yes')
        continue
    if a%2 == 0 and b%2 == 0 and d %2 == 0 and b-c == 2:
        print('Yes')
        continue
    GCD = gcd(b,d)
    if b-GCD +(a%GCD) > c:
        print('No')
    else:
        print('Yes')

Submission status: Accepted

Solution code:
from math import floor
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
T = int(input())
for i in range(T):
    A,B,C,D = map(int,input().split())
    if B > D or B > A:
        print("No")
    else:
        if A%B>C:
            print("No")
        else:
            d = gcd(B,D%B)
            r = (A%B)%d
            if B - d + r > C:
                print("No")
            else:
                print("Yes")

Submission status: Accepted

Solution code:
t = int(input())

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

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

for a, b, c, d in abcdt:
  if a < b:
    print('No')
  elif d < b:
    print('No')
  else:
    if d - b != 0:
      g = gcd(b, d - b)
    else:
      g = b
    if (a - c - 1) // g >= - ((-(a - b + 1)) // g):
      print('No')
    else:
      print('Yes')

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from fractions import gcd

def ng(a, b, c, add):
    return 0 < (b-a)%add < (b-c)

def solve():
    a, b, c, d = map(int, input().split())
    # 自明
    if d < b or a < b:
        return 'No'
    if c > b:
        return 'Yes'
    a %= b
    if a > c:
        return 'No'

    if d-b == 0:
        return 'Yes'

    if gcd(b, d-b) < b-c:
        return 'No'
    else:
        return 'Yes'
    # if ng(a, b, c, d-b):
    #     return 'No'

    # # さんざんまわしたらアウトになる
    # t = (d-b)
    # if ng(a, b, c, :
    #     return 'No'
    
    # return 'Yes' 
    
T = int(input())
for _ in range(T):
    print(solve())

Submission status: Accepted

Solution code:
def main():
    import math

    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    N = int(input())
    ABCD = [list(map(int, input().split())) for i in range(N)]
    for A,B,C,D in ABCD:
        # 在庫が買う本数以下 or 在庫追加が買う本数以下
        if A < B or D < B:
            print("No")
            continue

        A %= B
        # 在庫が買う本数以下になり、補給出来ない
        if C < A:
            print("No")
            continue
        if B == D:
            print("Yes")
            continue

        flag = True
        #print((B-A-1)%(D-B) ,">", (B-1)-(C+1))
        if (B-A-1)%(gcd(D,B)) <= (B-1)-(C+1):
            flag = False
        
        print("Yes" if flag else "No")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
N = int(input())
x = []
for i in range(N):
    a1,b1,c1,d1=[int(i) for i in input().split()]
    x.append([a1,b1,c1,d1])
for i in range(N):
  y = x[i]
  if y[0] < y[1]:
    print("No")
  elif y[1] > y[3]:
    print("No")
  elif y[1] > y[2]:
    ama = y[0] % y[1]
    mo = y[3] %  y[1]
    if mo == 0:
      if ama<= y[2]:
        print("Yes")
      else:
          print("No")
    elif mo <= y[1]-y[2]-1:
      print("No")
    else:
        to = y[1] % mo
        if to == 0:
          if ama<= y[2]:
            print("Yes")
          else:
              print("No")
        else:
          are = fractions.gcd(to, y[1])
          if are <= y[1]-y[2]-1:
            print("No")
          else:
            print("Yes")
          
  else:
    print("Yes")

Submission status: Accepted

Solution code:

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


T = int(input())

for _ in range(T):
    A, B, C, D = map(int, input().split())
    if (A < B) or (D < B):
        print('No')
        continue
    elif (C+1 >= B):
        print('Yes')
        continue
    else:
        s_res = A % B
        s_k = int((C + 1 - s_res - 0.1) // B + 1)
        X = gcd(B, (D%B))
        if X == 1:
            print('No')
            continue
        else:
            s_0 = s_k * B + s_res
            if (s_0 - (C+1)) % X > (B-C-2):
                print('Yes')
            else:
                print('No')

Submission status: Accepted

Solution code:
T = int(input())

ABCD = []
for i in range(T):
    a,b,c,d = map(int,input().split())
    ABCD.append((a,b,c,d))

for abcd in ABCD:
    a,b,c,d = abcd
    # 初日にダメになる
    if a < b:
        print("No")
    # 在庫補充が追いつかない
    elif d < b:
        print("No")
    # 補充タイミングが十分に早い
    elif c >= b:
        print("Yes")
    else:
        #print(a,b,c,d,a%b,d%b)
        e = a%b
        f = d%b
        list = [a]
        if f==0:
            if c<e<b:
                print("No")
            else:
                print("Yes") 
        else:
            cnt = 0
            while cnt < 100:
                g = ((c-e)//f+1)*f+e
                if g < b:
                    print("No")
                    cnt += 10000
                else:
                    if g in list:
                        print("Yes")
                        cnt += 10000
                    else:
                        list.append(g)
                        a = g
                        e = a%b
                        f = d%b
                        cnt += 1

Submission status: Accepted

Solution code:
from fractions import gcd

def solve(a, b, c, d):
    if d < b: return False
    g = gcd(d, b)
    a, ar = divmod(a, g)
    c, cr = divmod(c, g)
    d /= g
    b /= g
    if ar > cr: c -= 1
    if a < b: return False
    return c >= b - 1

for cas in xrange(input()):
    print 'Yes' if solve(*map(int, raw_input().split())) else 'No'

Submission status: Accepted

Solution code:
from fractions import gcd
T=input()
def check(a,b,c,d):
	a-=b
	if a<0: return 0
	if d<b: return 0
	if d>=b:
		if c>=b-1: return 1
		else:
			d=gcd(b,d)
			a%=d
			l=c+d-a
			r=b+d-a-1
#			print l,r,d
			if l/d<r/d:
				return 0
			else:
				return 1
			# l<=a + t * d<=r
for i in xrange(T):
	a,b,c,d=map(int,raw_input().split())
	if check(a,b,c,d):
		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(raw_input())

for i in range(T):
    A,B,C,D = map(int,raw_input().split())
    if A<B:
        print 'No'
    elif B>D:
        print 'No'
    elif C>=B:
        print 'Yes'
    else:
        if A%B>C:
            print 'No'
        elif D%B==0:
            print 'Yes'
        elif gcd(D%B,B)>=B-C and ( (B-A%B)%(D%B)>=B-C or (B-A%B)%(D%B)==0):
            print 'Yes'
        else:
            print 'No'

Submission status: Accepted

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

t=int(input())
for sdghsoewrgoijof in range(t):
    s=input().split()
    a,b,c,d=int(s[0]),int(s[1]),int(s[2]),int(s[3])
    if a<b or d<b:
        print("No")
        continue
    if a==b:
        if d<b:
            print("No")
            continue
        elif d==b:
            print("Yes")
            continue
        else:
            a=d
    if a%b>c:
        print("No")
        continue
    if d%b==0:
        print("Yes")
    else:
        g=gcd(b,d)
        if b+(a%g)-g>c:
            print("No")
        else:
            print("Yes")

Submission status: Accepted

Solution code:
import math

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

for i in range(t):
    if abcd[i][0] < abcd[i][1]:
        print("No")
    elif abcd[i][1] > abcd[i][3]:
        print("No")
    elif abcd[i][3] % abcd[i][1] == 0:
        if abcd[i][0] % abcd[i][1] > abcd[i][2]:
            print("No")
        else:
            print("Yes")
    else:
        big, small = abcd[i][1], abcd[i][3]
        while big % small:
            big, small = small, big % small
        gcd = small
        if abcd[i][1] - gcd <= abcd[i][2]:
            print("Yes")
        else:
            print("No")