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

Solution code:
import math


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 = math.gcd(b, d)
        if g == 1:
            if b - 1 > 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: Runtime Error

Solution code:
import math


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 = math.gcd(b, d)
        if g == 1:
            if b - 1 > c:
                return 'No'
        else:
            if (b - g) > c:
                return 'No'
#        if a % b > c:
#            return 'No'
#        if d % b == 0:
#            return 'Yes'
#        if b % 2 == 0 and d % 2 == 0:
#            if (d - b) % (b - c) == 0:
#                return 'Yes'
#            else:
#                return 'No'
#        else:
#            if b - c > 1:
#                return 'No'
#        if b % 2 == 1 or a % 2 == 1 or d % 2 == 1:
#            if b - c > 1:
#                return 'No'
#        else:
#            if (d - b) % (b - c) == 0:
#                return 'Yes'
#            else:
#                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: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
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]
    _a = a
    is_ok = True
    for j in range(10000):
        if b > a:
            is_ok = False
            break
        if b > d:
            is_ok = False
            break
        if c > b:
            is_ok = True
            break
        g = math.gcd(b, d)
        max_mod_b = b - g + a % g
        if max_mod_b > c:
            print('No')
        else:
            print('Yes')

Submission status: Runtime Error

Solution code:
import math
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]
    _a = a
    is_ok = True
    for j in range(10000):
        if b > a:
            is_ok = False
            break
        if b > d:
            is_ok = False
            break
        if c > b:
            is_ok = True
            break
        g = math.gcd(b, d)
        max_mod_b = b - g + a & g
        if max_mod_b > c:
            print('Yes')
        else:
            print('No')

Submission status: Runtime Error

Solution code:
def gcd(x,y):
    a = min(x,y)
    b = max(x,y)
    if a == 1:
        return(1)
    else:
        r = b%a
        if r==0:
            return(a)
        else:
            return(gcd(a,r))
N=int(input())
def solve(a,b,c,d):
    if b>d:
        return("No")
    if b>a:
        return("No")
    if b<=c:
        return("Yes")
    if c+1>=b:
        return("Yes")
    if b==d:
        if a<=b+c:
            return("Yes")
        else:
            x=b+c-(b+c-a)%b
            if x<b:
                return("No")
    g = gcd(d-b,b)
    x = (a-b-c-1)%g + b+c+1
    if x-b>=b:
        return("Yes")
    else:
        return("No")
for _ in range(N):
    a,b,c,d=map(int,input().split())
    print(solve(a,b,c,d))

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
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 = math.gcd(B,D)
    if (B - g + A % g) >C :
        print("No")
    else:
        print("Yes")

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
colomns = int(stdin.readline().rstrip())
datas = [stdin.readline().rstrip().split() for _ in range(1,colomns+1,1)]
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 = math.gcd(B,D)
    if (B - g + A % g) >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())
    
    Q = A%B
    R = (C-Q)%(D-B)
    
    
    if A-B <= 0 :
        print("No")
    elif B <= C :
        print("Yes")
    elif C+R == C :
        if C+D < B :
            print("No")
        else :
            print("Yes")
    elif C+R <B :
        print("No")
    else :
        print("Yes")

Submission status: Runtime Error

Solution code:
import math
T = int(input())
A, B, C, D = [0 for i in range(T)], [0 for i in range(T)], [0 for i in range(T)], [0 for i in range(T)]
for i in range(T):
    A[i], B[i], C[i], D[i] =  list(map(int, input().split()))

def judge(a, b, c, d):

    if a < b: # そもそも初日から買えない
        return "No"
    if b > d:
        return "No"
    
    Seq = []
    n = (a - c)  //  b # 初期のあたりをつける
    z = a - n*b
    if z <= c:
        z += c
#    z = a　- n * b
    Seq.append(z)
#    print('in z=', z, " n=", n )
    cnt = 0
    re = "No"
    while z >= b:
        z -= b
        if z <= c:
            z += d
        cnt += 1
        if z in Seq:
            re = "Yes"
            break
        if z == a:
            re = "Yes"
            break
        # 大きい数対策
        n = (z - c) // b
        z = z - n * b
#        print('z=', z, " n=", n )
        if z <= c:
            z += d
            
        print(z, '--' , Seq)
        if z in Seq:
            print(Seq)
            re = "Yes"
            break
        else:
            Seq.append(z)
    return re

for i in range(T):
    print(judge(A[i], B[i], C[i], D[i]))

Submission status: Runtime Error

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

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")
    elif b > d:
        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:
def gcd(a,b):
     
    # Everything divides 0 
    if (a == 0 or b == 0):
        False
    # base case
    if (a == b):
        return a
 
    # a is greater
    if (a > b):
        return gcd(a-b, b)
    return gcd(a, b-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: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
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-math.gcd(b,d)+a%math.gcd(b,d)<=c):print("Yes")
    else:print("No")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Solution code:
import math

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

  delta = d - b

  if delta < 0:
    print("No")
    continue

  b2 = b - c

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

  if b2 <= 1:
    print("Yes")
    continue

  pos = ((a-c)%b)

  if delta == 0:
    if pos > 0 and pos < b2:
      print("No")
      continue
    else:
      print("Yes")
      continue

  gcd = math.gcd(b, delta)

  if gcd == 1:
    print("No")
    continue

  pos_mod = pos%gcd
  if pos_mod > 0 and pos_mod < b2:
    print("No")
    continue
  print("Yes")

Submission status: Runtime Error

Solution code:
import math

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

  delta = d - b

  if delta < 0:
    print("No")
    continue

  b2 = b - c

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

  if b2 <= 1:
    print("Yes")
    continue

  pos = ((a-c)%b)

  if delta == 0:
    if pos > 0 and pos < b2:
      print("No")
      continue
    else:
      print("Yes")
      continue

  gcd = math.gcd(b, delta)

  if gcd == 1:
    print("No")
    continue

  # print(pos,b,gcd)

  pos_mod = pos%gcd
  if pos_mod > 0 and pos_mod < b2:
    print("No")
    continue
  print("Yes")

  # s = set()
  # s.add(pos)


  # for _ in range(b):
  #   pos += delta
  #   pos = pos%b
  #   # print(pos)

  #   if pos > 0 and pos < b2:
  #     print("No")
  #     break

  #   # print(pos, delta)
  #   if pos in s:
  #     print("Yes")
  #     break

  #   s.add(pos)


  # else:
  #   print("Yes")

Submission status: Runtime Error

Solution code:
import math

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

  delta = d - b

  if delta < 0:
    print("No")
    continue

  b2 = b - c

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

  if b2 <= 1:
    print("Yes")
    continue

  pos = ((a-c)%b)

  if delat == 0:
    if pos > 0 and pos < b2:
      print("No")
      continue
    else:
      print("Yes")
      continue

  gcd = math.gcd(b, delta)

  if gcd == 1:
    print("No")
    continue

  # print(pos,b,gcd)

  pos_mod = pos%gcd
  if pos_mod > 0 and pos_mod < b2:
    print("No")
    continue
  print("Yes")

  # s = set()
  # s.add(pos)


  # for _ in range(b):
  #   pos += delta
  #   pos = pos%b
  #   # print(pos)

  #   if pos > 0 and pos < b2:
  #     print("No")
  #     break

  #   # print(pos, delta)
  #   if pos in s:
  #     print("Yes")
  #     break

  #   s.add(pos)


  # else:
  #   print("Yes")

Submission status: Runtime Error

Solution code:
import math

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

  delta = d - b

  if delta < 0:
    print("No")
    continue

  b2 = b - c

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

  if b2 <= 1:
    print("Yes")
    continue

  pos = ((a-c)%b)


  gcd = math.gcd(b, delta)

  if gcd == 1:
    print("No")
    continue

  # print(pos,b,gcd)

  pos_mod = pos%gcd
  if pos_mod > 0 and pos_mod < b2:
    print("No")
    continue
  print("Yes")

  # s = set()
  # s.add(pos)


  # for _ in range(b):
  #   pos += delta
  #   pos = pos%b
  #   # print(pos)

  #   if pos > 0 and pos < b2:
  #     print("No")
  #     break

  #   # print(pos, delta)
  #   if pos in s:
  #     print("Yes")
  #     break

  #   s.add(pos)


  # else:
  #   print("Yes")

Submission status: Runtime Error

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 = B-g+A%g
    if maximum > C:
      print 'No'
    else:
      print 'Yes'

Submission status: Runtime Error

Solution code:
def gcd(m, n):
    return m if n == 1 else gcd(n, m % n)


def judge(a, b, c, d):
    if a < b or b > d:
        return False

    else:
        m = a - (a // b) * b

        if m > c:
            return False

        else:
            if b == d:
                return True
            else:
                i = m // gcd(d - b, b)
                m = (d - b) * (1 + c // (d - b))
                for j in range((b - m) // i):
                    m += i
                    if m < b:
                        return False
                    else:
                        return True




def run():
    T = int(input())

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

        if judge(A, B, C, D):
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    run()

Submission status: Runtime Error

Solution code:
import math
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-math.gcd(B,D)+(A%math.gcd(B,D)):
        ans = "No"


    print(ans)
    L = []

Submission status: Runtime Error

Solution code:
#
import sys
from fraction import gcd

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:
        flag=1
        p= gcd(b[i],d[i])
        if (b[i]-p)+a[i]%p > c[i]:
            print("No")
        else:
            print("Yes")

Submission status: Runtime Error

Solution code:
#
import sys
from math import gcd

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:
        flag=1
        p= gcd(b[i],d[i])
        if (b[i]-p)+a[i]%p > c[i]:
            print("No")
        else:
            print("Yes")

Submission status: Runtime Error

Solution code:
import math
t = int(input())
c = [list(map(int,input().split())) for i in range(t)]
for i in range(t):
    mem1 = c[i][0] % c[i][1]
    mem2 = c[i][3] % c[i][1]
    mem3 = math.gcd(c[i][1],c[i][3])
    while 1 :
        if c[i][0] < c[i][1]:
            print("No")
            break; 
        elif c[i][3] < c[i][1]:
            print("No")
            break;      
        elif mem2 == 0 :
            if c[i][1] - c[i][2] > 1 and c[i][2] < mem1 < c[i][1]:
                print("No")    
                break;
            else :
                print("Yes")
                break;
        elif c[i][1] - c[i][2] == 1 :
            print("Yes")
            break;
        elif  mem3 < (mem1 % mem3) + c[i][1] - c[i][2]:
            print("No")
            break;
        elif mem2 % 2 == 1 and c[i][1] - c[i][2] > 1:
            print("No")  
            break;          
        else :
            print("Yes")
            break;

Submission status: Runtime Error

Solution code:
#
import sys
from math import *
import numpy as np
import itertools

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:
        flag=1
        p= gcd(b[i],d[i])
        if (b[i]-p)+a[i]%p > c[i]:
            print("No")
        else:
            print("Yes")

Submission status: Runtime Error

Solution code:
#
import sys
import math
import numpy as np
import itertools

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:
        flag=1
        p= math.gcd(b[i],d[i])
        if (b[i]-p)+a[i]%p > c[i]:
            print("No")
        else:
            print("Yes")

Submission status: Runtime Error

Solution code:
t = int(input())

for _ in range(t):
    a, b, c, d = map(int, input().split())
    cond = True
    
    if a < b or b > d or (a % b) > c:
        cond = False
        
    if cond:
        if b < d and b > (c + 1):
            coef = ((c - (a % b)) // (d % b)) + 1
            tmp = (a % b) + coef * (d % b)
            if tmp > c and tmp < b:
                cond = False
    
    if cond:
        print('Yes')
    else:
        print('No')

Submission status: Runtime Error

Solution code:
import math

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

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

Solution code:
import math

# input
T = int(input())
J = [list(map(int, input().split())) for _ in range(T)]

def juice(A_int, A, B, C, D):
    if A < B:
        ans = 'No'
        return ans
    if A <= B + C:
        if D == B:
            ans = 'Yes'
            return ans
        if D < B:
            ans = 'No'
            return ans
        l = math.floor((B + C - A) / (D - B) + 1)
        A = A + l * (D - B) # AをB+Cより大きくする
        if A in A_int:
            ans = 'Yes'
            return ans
        A_int.add(A)
        return juice(A_int, A, B, C, D)
    else:
        k = math.ceil((A - C) / B)
        A = A - k * B
        if A < 0:
            ans = 'No'
            return ans
        if (A + D) in A_int:
            ans = 'Yes'
            return ans 
        A_int.add(A + D)
        return juice(A_int, A + D, B, C, D)

for i in range(T):
    A_int = set([J[i][0]])
    A = J[i][0]
    B = J[i][1]
    C = J[i][2]
    D = J[i][3]
    print(juice(A_int, A, B, C, D))

Submission status: Runtime Error

Solution code:


import math
import fraction
aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


def so(p,q):
  while p!=q:
    if p>q:
      p-=q
    else:
      q-=p
  return p


#print(so(11,5))

def aaa(n):

  a=int(N[n][0])
  b=int(N[n][1])
  c=int(N[n][2])
  d=int(N[n][3])

  e=a-a//b*b
  f=d-d//b*b
  
  if e*f>0 :
    s=fraction.gcd(e,f)
  else :
    s=f


  if a<b or d<b :
    return "No"
  
  elif b<=c :
    return "Yes"
  else:
  
    if f!=0 :
      ss=b//s*s
      if ss==b:
        ss-=s

      if ss>c:
        return "No"
          
    

        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        return "No"

  return "Yes"

for i in range(aa):
  print(aaa(i))

Submission status: Runtime Error

Solution code:


import math
aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


def so(p,q):
  while p!=q:
    if p>q:
      p-=q
    else:
      q-=p
  return p


#print(so(11,5))

def aaa(n):

  a=int(N[n][0])
  b=int(N[n][1])
  c=int(N[n][2])
  d=int(N[n][3])

  e=a-a//b*b
  f=d-d//b*b
  
  if e*f>0 :
    s=math.gcd(e,f)
  else :
    s=f


  if a<b or d<b :
    return "No"
  
  elif b<=c :
    return "Yes"
  else:
  
    if f!=0 :
      ss=b//s*s
      if ss==b:
        ss-=s

      if ss>c:
        return "No"
          
    

        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        return "No"

  return "Yes"

for i in range(aa):
  print(aaa(i))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
def solve(a,b,c,d):
    if b==d:
        if a<=b+c:
            return("Yes")
        else:
            x=b+c-(b+c-a)%b
            if x<b:
                return("No")
    if b>d:
        return("No")
    if b>a:
        return("No")
    if b<=c:
        return("Yes")
    if c+1>=b:
        return("Yes")
    g = math.gcd(d-b,b)
    x = (a-b-c-1)%g + b+c+1
    if x-b>=b:
        return("Yes")
    else:
        return("No")
for _ in range(N):
    a,b,c,d=map(int,input().split())
    print(solve(a,b,c,d))

Submission status: Runtime Error

Solution code:


import math
aa=int(input())
N=[0 for i in range(aa)]
for i in range(aa):
  bb=input()
  #print(b)
  N[i]=bb.split()


def so(p,q):
  while p!=q:
    if p>q:
      p-=q
    else:
      q-=p
  return p


#print(so(11,5))

def aaa(n):

  a=int(N[n][0])
  b=int(N[n][1])
  c=int(N[n][2])
  d=int(N[n][3])

  e=a-a//b*b
  f=d-d//b*b
  
  if e*f>0 :
    s=gcd(e,f)
  else :
    s=f


  if a<b or d<b :
    return "No"
  
  elif b<=c :
    return "Yes"
  else:
  
    if f!=0 :
      ss=b//s*s
      if ss==b:
        ss-=s

      if ss>c:
        return "No"
          
    

        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        return "No"

  return "Yes"

for i in range(aa):
  print(aaa(i))

Submission status: Runtime Error

Solution code:
import math
# 最小公倍数
def lcm(a, b):
    return a * b // math.gcd(a, b)

t = int(input())
c = [list(map(int,input().split())) for i in range(t)]
for i in range(t):
    mem1 = c[i][0] % c[i][1]
    mem2 = c[i][3] % c[i][1]
    mem3 = (c[i][1]-1) % lcm(c[i][1],c[i][3])
    while 1 :
        if c[i][0] < c[i][1]:
            print("No")
            break; 
        elif c[i][3] < c[i][1]:
            print("No")
            break;      
        elif mem2 == 0 :
            if c[i][1] - c[i][2] > 1 and c[i][2] < mem1 < c[i][1]:
                print("No")    
                break;
            else :
                print("Yes")
                break;
        elif c[i][1] - c[i][2] == 1 :
            print("Yes")
            break;
        elif  mem3 < mem1 + c[i][1] - c[i][2]:
            print("No")
            break;
        elif mem2 % 2 == 1 and c[i][1] - c[i][2] > 1:
            print("No")  
            break;          
        else :
            print("Yes")
            break;

Submission status: Runtime Error

Solution code:
import math
N=int(input())
def solve(a,b,c,d):
    if b==d:
        if a<=b+c:
            return("Yes")
        else:
            x=b+c-(b+c-a)%b
            if x<b:
                return("No")
    if b>d:
        return("No")
    if b>a:
        return("No")
    if b<=c:
        return("Yes")
    if c+1>=b:
        return("Yes")
    
    
    g = math.gcd(d-b,b)
    x = (a-b-c-1)%g + b+c+1
    if x-b>=b:
        return("Yes")
    else:
        return("No")
for _ in range(N):
    a,b,c,d=map(int,input().split())
    print(solve(a,b,c,d))

Submission status: Runtime Error

Solution code:
#coding:utf-8
import math
gcd = math.gcd

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")
    else:
        if c >= b:
            print("Yes")
        else:
            success = 0
            if gcd(a,d) == 1:
                print("No")
                success = 1
            if success == 0:

                uni = d//b
                sur = a % b
                while sur != a:
                    if (a-d) % b > a % b:
                        a += uni * d
                    else:
                        a += d
                    if c < a % b:
                        print("No")
                        break
                    a %= b
                else:
                    print("Yes")

Submission status: Runtime Error

Solution code:
import math

# input
T = int(input())
J = [list(map(int, input().split())) for _ in range(T)]

def juice(A_int, A, B, C, D):
    if A < B:
        ans = 'No'
        return ans
    if A <= B + C:
        if D == B:
            ans = 'Yes'
            return ans
        if D < B:
            ans = 'No'
            return ans
        l = math.floor((B + C - A) / (D - B) + 1)
        A = A + l * (D - B) # AをB+Cより大きくする
        print(l, A)
        if A in A_int:
            ans = 'Yes'
            return ans
        A_int.add(A)
        return juice(A_int, A, B, C, D)
    else:
        k = math.ceil((A - C) / B)
        A = A - k * B
        print(k, A)
        if A < 0:
            ans = 'No'
            return ans
        if (A + D) in A_int:
            ans = 'Yes'
            return ans 
        A_int.add(A + D)
        return juice(A_int, A + D, B, C, D)

for i in range(T):
    A_int = set([J[i][0]])
    A = J[i][0]
    B = J[i][1]
    C = J[i][2]
    D = J[i][3]
    print(juice(A_int, A, B, C, D))

Submission status: Runtime Error

Solution code:
# Q_B
import math
T = int(input())
A, B, C, D = [0 for i in range(T)], [0 for i in range(T)], [0 for i in range(T)], [0 for i in range(T)]
for i in range(T):
    A[i], B[i], C[i], D[i] =  list(map(int, input().split()))

def judge(a, b, c, d):

    if a < b: # そもそも初日から買えない
        return "No"
    if b > d:
        return "No"
    
    Seq = []
    n = (a - c)  //  b # 初期のあたりをつける
    z = a - n*b
    if z <= c:
        z += c
#    z = a　- n * b
    Seq.append(z)
#    print('in z=', z, " n=", n )
    cnt = 0
    re = "No"
    while z >= b:
        z -= b
        if z <= c:
            z += d
        cnt += 1
        if z in Seq:
            re = "Yes"
            break
        if z == a:
            re = "Yes"
            break
        # 大きい数対策
        n = (z - c) // b
        z = z - n * b
        print('z=', z, " n=", n )
        if z <= c:
            z += d
            
        print(z, '--' , Seq)
        if z in Seq:
            print(Seq)
            re = "Yes"
            break
        else:
            Seq.append(z)
    return re

for i in range(T):
    print(judge(A[i], B[i], C[i], D[i]))

Submission status: Runtime Error

Solution code:
import math as m
N=int(input())
def solve(a,b,c,d):
    if b==d:
        if a<=b+c:
            return("Yes")
        else:
            x=b+c-(b+c-a)%b
            if x<b:
                return("No")
    if b>d:
        return("No")
    if b>a:
        return("No")
    if b<=c:
        return("Yes")
    if c+1>=b:
        return("Yes")
    
    
    g = m.gcd(d-b,b)
    x = (a-b-c-1)%g + b+c+1
    if x-b>=b:
        return("Yes")
    else:
        return("No")
for _ in range(N):
    a,b,c,d=map(int,input().split())
    print(solve(a,b,c,d))