Problem:


Score : 600 points

Problem Statement

Ringo Mart, a convenience store, sells apple juice.

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

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

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

Constraints

1 \leq T \leq 300

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

All values in input are integers.

Input

Input is given from Standard Input in the following format:

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

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

Output

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

Sample Input 1

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

Sample Output 1

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

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

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

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

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

and so on, thus Snuke can buy juice indefinitely.

Sample Input 2

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

Sample Output 2

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



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


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

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
abcd = [[int(i) for i in input().split()] for i in range(t)] 
counter = 0
for qu in abcd:
    if qu[0] < qu[1]:
        print("No")
    elif qu[1]-1<=qu[2]:
        if qu[3] < qu[1]:
            print("No")
        else:
            print("Yes")
    else:
        amod = qu[0]%qu[1]
        dmod = qu[3]%qu[1]
        deadzone = range(qu[2]+1,qu[1])
        cycle = []
        flag = True
        while(flag):
            if amod in deadzone:
                print("No")
                flag = False
            elif cycle != []:
                if amod == cycle[0]:
                    print("Yes")
                    flag = False
            else:
                if cycle == []:
	                cycle.append(amod)
            amod = (amod + dmod) % qu[1]

Submission status: Time Limit Exceeded

Solution code:
T = int(input())
for i in range(T):
	A, B, C, D = list(map(int, input().split()))
	memo = set()
	x = A
	while True:
		x -= B
		if x < 0:
			print("No")			
			break 
		x -= B*(x // B)
		if x <= C:
			x += D
		if x in memo:
			print("Yes")
			break
		memo.add(x)

Submission status: Time Limit Exceeded

Solution code:
num_example = int(input())

for _ in range(0, num_example):
    input_line = input().split()
    initial_lot, num_purchase, feed_line, feed = tuple(map(int, input_line))
    lots = [initial_lot]

    lot = initial_lot

    while True:
        # init
        # print(f"INIT: {lot}")
        available = lot - feed_line
        if available > num_purchase:
            purchase = available // num_purchase
        else:
            purchase = 1

        lot -= purchase * num_purchase

        # print(f"lot:{lot}")
        if lot < 0:
            print("No")
            break
        elif lot <= feed_line:
            # print(f"ADD: {feed}")
            lot += feed

        if lot in lots:
            print("Yes")
            break
        else:
            lots.append(lot)

Submission status: Time Limit Exceeded

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




for i in range(aa):

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

  e=a-a//b*b
  f=d-d//b*b
  

  h=0 #YES=0 NO=1


  if a<b or d<b :
    h=1
  else:

  
    if f!=0 :
      while e<b:
        if e>c :
          h=1
        e+=f
        #print(e)
        #print(f)
  #print("while")
    else:
      if e>c :
        h=1
        e+=f

  

  if h==1:
    print("No")
  else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
def main():
  t = int(input())
  for _ in range(t):
    a, b, c, d = map(int, input().split())
    if (a < b or d < b):
      print("No")
      continue
    if (c >= b):
      print("Yes")
      continue
  
    lst = []
    d %= b
    while True:
      a %= b
      if a > c:
        print("No")
        break
      if a in lst:
        print("Yes")
        break
      lst.append(a)
      a += d
main()

Submission status: Time Limit Exceeded

Solution code:
T = int(input())
for _ in range(T):
    A, B, C, D = map(int, input().split())
    pre = set()
    if A//B>0:
        A = A%B
        A += B
    if D//B>0:
        D = D%B
        D += B
    pre.add(A)
    while 1:
        A = A-B
        if A < 0:
            print('No')
            break
        if  A <= C:
            A += D
        if A in pre:
            print('Yes')
            break
        pre.add(A)

Submission status: Time Limit Exceeded

Solution code:
T=int(input())

for cnt in range(T):
  A,B,C,D=map(int,input().split())
  if(B > D or A < B):
    print("No")
    continue
  if(B <= C):
    print("Yes")
    continue

  A = A % B + B
  Zaiko = A
  lista = []
  i = 0
  while(i < 10000):
    Zaiko = Zaiko - B
    #print(Zaiko)
    if(Zaiko < 0):
      print("No")
      break
    if(Zaiko <= C):
      Zaiko += D
      Zaiko = Zaiko % B + B
    if(Zaiko in lista ):
      print("Yes")
      break
    lista.append(Zaiko)
    i += 1
    if(i == 10000):
      print("Yes")
  #print(A,B,C,D)

Submission status: Time Limit Exceeded

Solution code:
t = input()
result = []
hist = []
for i in range(int(t)):
	data = input().split()
	a = int(data[0])
	b = int(data[1])
	c = int(data[2])
	d = int(data[3])
	hist.clear()
	while True:
		if a < b:
			result.append("No")
			break
		n = int((a / b))
		a -= b * n
		if a <= c:
			a += d
		if a in hist:
			result.append("Yes")
			break
		else:
			hist.append(a)
for i in range(int(t)):
	print(result[i])

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
abcd = [[int(i) for i in input().split()] for i in range(t)] 
counter = 0
for qu in abcd:
    if qu[0] < qu[1]:
        print("No")
    elif qu[1]-1<=qu[2]:
        if qu[3] < qu[1]:
            print("No")
        else:
            print("Yes")
    else:
        amod = qu[0]%qu[1]
        dmod = qu[3]%qu[1]
        deadzone = range(qu[2]+1,qu[1])
        cycle = []
        flag = True
        while(flag):
            if amod in deadzone:
                print("No")
                flag = False
            elif amod in cycle:
                print("Yes")
                flag = False
            else:
                cycle.append(amod)
                amod = (amod + dmod) % qu[1]

Submission status: Time Limit Exceeded

Solution code:
T = int(input())

def calc(A,B,C,D):
    list_ = []
    while not A in list_:
        if A<B : return False
        if A%B > C : return False
        A %= B
        if A in list_:
            return True
        list_.append(A)
        if A+D < B: return False
        A+=D

input_list = []
for _ in range(T):
    input_list.append(input())
    
for inp in input_list:
    A,B,C,D = map(int,inp.split())
    if calc(A,B,C,D):
        print("Yes")
    else:
        print("No")

Submission status: Time Limit Exceeded

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

for a,b,c,d in ABCD:
    count = 0
    dp = [a]
    now = a
    for _ in range(c+2):
        if now < b:
            print('No')
            break
        now %= b
        if now in dp:
            print('Yes')
            break
        if now > c:
            print('No')
            break
        dp.append(now)
        now += d

Submission status: Time Limit Exceeded

Solution code:
#B
import math
T=int(input())
for i in range(T):
    check=0
    A,B,C,D=map(int,input().split())
    A_list=[]
    if B>D:
        print('No')
        check=1
    while check==0:
        k=math.ceil((A-C)/B) if A>=C else 1
        A-=k*B
        if A<0:
            print('No')
            break
        elif A<=C:
            A+=D
            if A in A_list:
                print('Yes')
                break
            A_list.append(A)

Submission status: Time Limit Exceeded

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

from math import ceil, floor

def solve():
    n = int(input())
    ans = []
    for i in range(n):
        l = []
        a, b, c, d = map(int, input().split())
        while True:
            if a <= c:
                t = a - b
                if t < 0:
                    ans.append('No')
                    break
                l.append(t)
                a = t + d
                continue
            f = ceil((a / b) - (c / b))
            if f <= 0:
                ans.append('No')
                break
            t = a - b * f
            while t > c:
                t -= b
            if l.count(t) > 2:
                ans.append('Yes')
                break
            if t < 0:
                ans.append('No')
                break
            l.append(t)
            a = t + d
    print('\n'.join(ans))

if __name__=="__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
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
  visited=[]
  while True:
    a = c+(a-c)%b
    if a>c and a<b:
      print('No')
      break
    elif a == c:
      if c in visited:
        print('Yes')
        break
      visited.append(a)
    else:
      a = a-b
      if a in visited:
        print('Yes')
        break
      visited.append(a)
    a+=d

Submission status: Time Limit Exceeded

Solution code:
T = int(input())

counT = 0

def main():
    a = list(map(int,input().split()))
    A = a[0]
    B = a[1]
    C = a[2]
    D = a[3]

    #print(A,B,C,D)
    if A < B:
        return 0

    if B <= C and B <= D:
        return 1
    
    if B > D:
        return 0

    A = A % B

    count = 0

    while A  <  B:
        #print(A)
        if A > C and A < B:
            return 0
        if B==D and A < C:
            return 1
        if B==D and A >= C:
            return 1
        A += (D-B)
    return 1

while counT < T:
    if main() == 1:
        s = "Yes"
    else:
        s = "No"
    print(s)
    counT +=1

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
a = []
b = []
c = []
d = []
for i in range(t):
    tmp = list(map(int, input().split(" ")))
    a.append(tmp[0])
    b.append(tmp[1])
    c.append(tmp[2])
    d.append(tmp[3])

for i in range(t):
    if(a[i] < b[i]): print("No")
    elif(b[i] > d[i]): print("No")
    elif(b[i] <= c[i]): print("Yes")
    else:
        remain = a[i] - (a[i] // b[i]) * b[i]
        increase = d[i] - b[i]
        if(increase == 0):
            if(c[i] >= remain): print("Yes")
            elif(b[i] > remain): print("No")
            else: print("Yes")
        else:
            while(c[i] >= remain): remain += increase
            if(remain < b[i]): print("No")
            else: print("Yes")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
T = int(input())

counT = 0

def main():
    a = list(map(int,input().split()))
    A = a[0]
    B = a[1]
    C = a[2]
    D = a[3]

    #print(A,B,C,D)
    if A < B:
        return 0

    if B <= C and B <= D:
        return 1
    
    if B > D:
        return 0

    A = A % B

    count = 0

    while A  <  B:
        #print(A)
        if A > C and A < B:
            return 0
        if B==D and A < C:
            return 1
        A += (D-B)
    return 1




while counT < T:
    if main() == 1:
        s = "Yes"
    else:
        s = "No"
    print(s)
    counT +=1

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
for i in range(t):
	a,b,c,d = map(int,input().split())
	if a < b:
		print('No')
	else:
		a = a%b
		if d-b >= 0:
			add = (d-b)%b
		else:
			add = d-b
		check = [a]
		s = True
		while s:
			if add >= 0:
				if c >= b:
					print('Yes')
					s = False
				elif a+add <= c:
					if a+add in check:
						print('Yes')
						s = False
					else:
						check.append(a+add)
						a = a+add
				else:
					a = a+add-b
					if a < 0:
						print('No')
						s = False
					if a+add in check:
						print('Yes')
						s = False
					else:
						check.append(a+add)
						a = a+add
			else:
				print('No')
				s = False

Submission status: Time Limit Exceeded

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=min(a-c,mi+1+cnt)
  for i in range(mi+1,ma):
    if i%cnt==0:
      return True
  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: Time Limit Exceeded

Solution code:

def solve_sub(A,B,C,D):
    a = set((A,))
    while 1:
        A -= (max(1,(A-C)//B))*B
        #print(A,a)
        if A in a:
            b = 'Yes'
            break
        if A < 0:
            b = 'No'
            break
        a |= set((A,))
        A += D*(A<=C)
    return b

def solve():
    N = int(input())
    for i in range(N):
        A,B,C,D =  map(int,input().split())
        print(solve_sub(A,B,C,D))

if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding : utf-8 -*-

T = int(input())

for t in range(T):
    A,B,C,D = map(int, input().split())
    stock = A
    past = [stock,]
    while True:
        if stock < B:
            print("No")
            break
        stock = stock - B + D * (stock - B <=C)
        if stock in past:
            print("Yes")
            break
        past.append(stock)

Submission status: Time Limit Exceeded

Solution code:
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]
    mita = set()
    while True:
      if ama in mita:
        print("Yes")
        break
      mita.add(ama)
      if ama <= y[2] and ama>= 0:
        ama += y[3]
      if ama < y[1]:
        print("No")
        break
      ama %= y[1]
  else:
    print("Yes")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
T = int(input())
for _ in range(T):
  a,b,c,d = [int(_) for _ in input().split()]

  result = a-b  # 2
  while result >= 0:
    if result <= c:
      result += d
    result = result -b
    if result == (a-b):
      break
  if result < 0:
    print("No")
  elif result == (a-b):
    print("Yes")

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def nibun(func ,min_ ,max_ ):
    left = min_
    right= max_
    while not(left==right):
        mid = (left+right) //2
        tmp = func(mid)
        if tmp:
            right = mid
        else:
            left = mid+1
    return left


def solve(_input):
    A,B,C,D = list(map(int,_input.split()))
    if A<B  or D<B :
        return "No"
    #days = nibun((lambda x:A-x*B  <=  C) , 0, A )
    memo = set()
    memo.add(A)
    last = None
    while A>0:
        #days= 0
        #while A-B*days>C:
        #    days+=1
        days = nibun((lambda x: A - x * B <= C), 0, A)
        A = A-B*days
        if A<0:
            return "No"
        if A in memo:
            return "Yes"
        memo.add(A)
        days=1
        if last:
            days = nibun((lambda x: A + x * (D-B) >= C ), 1, 10000000000)
            #print("++++" , days)

        last = A
        #print("aaa", A)
        A+=D *days -B*(days-1)
    return "No"

    #print(A_new,days,A,B,C,D)
    if D< B:
        return "No"
    return "Yes"

N = int(input())

l = [ input()  for _ in range(N)]
for line in l:
    print(solve(line))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
t=[list(map(int,input().split()))for i in range(n)]
for i in range(len(t)):
    b=t[i][0]%t[i][1]
    g=False
    if t[i][0]-t[i][1]<0:print("No");continue
    while 1:
        t[i][0]%=t[i][1]
        if t[i][0]==b and g:print("Yes");break
        g=True
        if t[i][0]<=t[i][2]:t[i][0]+=t[i][3]
        if t[i][0]-t[i][1]<0:print("No");break

Submission status: Time Limit Exceeded

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

  mi=a-b
  ma=a-c
  cnt=gcd(b,d)
  for i in range(mi+1,ma):
    if i%cnt==0:
      return True
  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: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


def main_func(input_str):
    l = list(map(int, input_str.split(' ')))
    a = l[0]
    b = l[1]
    c = l[2]
    d = l[3]
    # 明らかにNGケース
    if a < b:
        print('No')
        return
    elif d < b:
        print('No')
        return

    
    # 初回でNG出すケース
    count_set = {}
    amari = a % b
    for i in range(c):
        try:
            if count_set[amari] == 1:
                break
        except KeyError:
            count_set[amari] = 1
        
        if amari > c:
            print('No')
            # print(amari, b, c)
            return
        amari = (amari + d) % b

    
    print('Yes')
    return

def main(n, input_list):
    for i in range(n):
        main_func(input_list[i])

if __name__ == '__main__':
    try:
        n = int(input().strip())
        input_list = []
        for i in range(n):
            input_list.append(input().strip())
        main(n, input_list)
    except EOFError:
        pass

Submission status: Time Limit Exceeded

Solution code:
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(10000000):
        if d < b:
            is_ok = False
            break
        
        if _a - b > c:
            _a = _a - (((_a - c) // b) - 1) * b
        _a = _a - b
        if _a < 0:
            is_ok = False
            break
        if _a <= c:
            _a += d
    if is_ok:
        print("Yes")
    else:
        print("No")

Submission status: Time Limit Exceeded

Solution code:
def main():
  t = int(input())
  for _ in range(t):
    a, b, c, d = map(int, input().split())
    if (a < b or d < b):
      print("No")
      continue
    if (c >= b):
      print("Yes")
      continue
  
    lst = []
    while True:
      a %= b
      if a > c:
        print("No")
        break
      if a in lst:
        print("Yes")
        break
      lst.append(a)
      a += d
main()

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
for i in range(t):
	a,b,c,d = map(int,input().split())
	if a < b:
		print('No')
	else:
		a = a%b
		if d-b >= 0:
			add = (d-b)%b
		else:
			add = d-b
		check = [a]
		s = True
		while s:
			if add >= 0:
				if a+add <= c:
					if a+add in check:
						print('Yes')
						s = False
					else:
						check.append(a+add)
						a = a+add
				else:
					a = a+add-b
					if a < 0:
						print('No')
						s = False
					if a+add in check:
						print('Yes')
						s = False
					else:
						check.append(a+add)
						a = a+add
			else:
				print('No')
				s = False

Submission status: Time Limit Exceeded

Solution code:
t = int(input())
for _ in range(t):
  a, b, c, d = map(int, input().split())
  if (a < b or d < b):
    print("No")
    continue
  if (c >= b):
    print("Yes")
    continue

  lst = []
  while True:
    a %= b
    if a > c:
      print("No")
      break
    if a in lst:
      print("Yes")
      break
    lst.append(a)
    a += d

Submission status: Time Limit Exceeded

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 b != d:
        if (b - c) > (d - b):
            cond = False
            
        if cond:
            for i in range(c + 1, b):
                if (i - (a % b)) % (d - b) == 0:
                    cond = False
                    break
    
        
    if cond:
        print('Yes')
    else:
        print('No')

Submission status: Time Limit Exceeded

Solution code:
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 = mem1
    cnt = 0
    while 1 :
        if c[i][0] < c[i][1]:
            print("No")
            break; 
        if c[i][3] < c[i][1]:
            print("No")
            break;            
        if cnt == c[i][1]:
            print("Yes")
            break;
        if c[i][2] < mem1 < c[i][1]:
            print("No")
            break;    
        cnt += 1
        mem1 += mem2 
        if mem1 == mem3:
            print("Yes")
            break;

Submission status: Time Limit Exceeded

Solution code:
def nibun(func ,min_ ,max_ ):
    left = min_
    right= max_
    while not(left==right):
        mid = (left+right) //2
        tmp = func(mid)
        if tmp:
            right = mid
        else:
            left = mid+1
    return left


def solve(_input):
    A,B,C,D = list(map(int,_input.split()))
    if A<B  or D<B :
        return "No"
    #days = nibun((lambda x:A-x*B  <=  C) , 0, A )
    memo = set()
    memo.add(A)
    while A>0:
        #days= 0
        #while A-B*days>C:
        #    days+=1
        days = nibun((lambda x: A - x * B <= C), 0, A)
        A = A-B*days
        if A<0:
            return "No"
        if A in memo:
            return "Yes"
        memo.add(A)
        A+=D
    print(A)
    return "No"

    #print(A_new,days,A,B,C,D)
    if D< B:
        return "No"
    return "Yes"

N = int(input())

l = [ input()  for _ in range(N)]
for line in l:
    print(solve(line))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def checkKaburi(arr, num):
    if num in arr:
        return True
    else:
        return False

T = int(input())
arr = []
for i in range(T):
    A,B,C,D = list(map(int,input().split()))
    noon = []
    bottle = A
    flag = True
    while 1:
        if checkKaburi(noon, bottle):
            break
        noon.append(bottle)
        num = ((bottle-C)//B + ((bottle-C)%B!=0))
        if num < 1:
            num = 1
        bottle -= num * B
        if bottle < 0:
            flag = False
            break
        if bottle <= C:
            bottle += D
    if flag:
        print('Yes')
    else:
        print('No')

Submission status: Time Limit Exceeded

Solution code:
T = int(input())

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

    if A < B or B > D:
        print("No") #そもそも買えないか、毎日補充したとしてもやがてなくなる
    else:
        if A%B > C: 
            print("No") #いつか、「補充基準以上だが買う数よりは少ない」状況となる
        else:
            if D%B == 0:
                print("Yes") #補充される前後で在庫の剰余は変わらないのでsustainable
            else:
                mod = A%B
                while mod <= C:
                    mod += D%B
                if mod >= B:
                    print("Yes")
                else:
                    print("No")

Submission status: Time Limit Exceeded

Solution code:

def main():
    t = int(input())
    A=[]
    B=[]
    C=[]
    D=[]

    for i in range(t):
        a,b,c,d = map(int,input().split())
        A.append(a)
        B.append(b)
        C.append(c)
        D.append(d)


    for i in range(t):
        ans = "Yes"

        if A[i] < B[i] or B[i] > D[i]:
            ans = "No"

        for j in range(B[i]):
            if (A[i] + (j*D[i])) % B[i] > C[i]:
                ans = "No"

        print(ans)


if __name__ == "__main__":
        main()

Submission status: Time Limit Exceeded

Solution code:
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):
    if Juice[i][0]<Juice[i][1]:
        print("No")
        return
    juice=Juice[i][0]
    juicelist=set()
    while True:
        juice=juice%Juice[i][1]
        #print(juice)
        if juice in juicelist:
            print("Yes")
            break
        else:
            juicelist=juicelist|{juice}
        if juice<=Juice[i][2]:
            juice+=Juice[i][3]
        #print(juice)
        if juice<Juice[i][1]:
            print("No")
            break

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

Submission status: Time Limit Exceeded

Solution code:
T=int(input())

for cnt in range(T):
  A,B,C,D=map(int,input().split())
  if(B>D or A < B):
    print("No")
    continue
  
  A = A % B + B
  Zaiko = A
  lista = []
  
  i = 0
  while(i < 10000):
    Zaiko = Zaiko - B
    if(Zaiko < 0):
      print("No")
      break
    if(Zaiko <= C):
      Zaiko += D
      Zaiko = Zaiko % B + B
    if(Zaiko in lista):
      print("Yes")
      break
    lista.append(Zaiko)
    i += 1
    if(i == 10000):
      print("Yes")
  #print(A,B,C,D)

Submission status: Time Limit Exceeded

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


def main_func(input_str):
    l = list(map(int, input_str.split(' ')))
    a = l[0]
    b = l[1]
    c = l[2]
    d = l[3]
    # 明らかにNGケース
    if a < b:
        print('No')
        return
    elif d < b:
        print('No')
        return

    
    # 初回でNG出すケース
    count_set = []
    amari = a % b
    for i in range(c):
        if amari in count_set:
            break
        else:
            count_set.append(amari)

        if amari > c:
            print('No')
            # print(amari, b, c)
            return
        amari = (amari + d) % b

    
    print('Yes')
    return

def main(n, input_list):
    for i in range(n):
        main_func(input_list[i])

if __name__ == '__main__':
    try:
        n = int(input().strip())
        input_list = []
        for i in range(n):
            input_list.append(input().strip())
        main(n, input_list)
    except EOFError:
        pass

Submission status: Time Limit Exceeded

Solution code:
if __name__ == "__main__":
    T = input().rstrip().split(' ')
    T = int(T[0])
    for t in range(T):
        line = input().rstrip().split(' ')
        A = int(line[0])
        B = int(line[1])
        C = int(line[2])
        D = int(line[3])
        A_list = []
        flag = False
        while True:
            if A in A_list:
                flag = True
                break
            A_list.append(A)
            if A < B:
                break
            mod = A % B
            A = mod
            if A <= C:
                A = A + D
        if flag:
            print('Yes')
        else:
            print('No')

Submission status: Time Limit Exceeded

Solution code:
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]
    mita = set()
    while True:
      if ama in mita:
        print("Yes")
        break
      mita.add(ama)
      if ama <= y[2] and ama>= 0:
        ama += y[3]
      if ama < y[1]:
        print("No")
        break
      ama %= y[1]
  else:
    print("Yes")

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8
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:
        sur = a % b
        while sur != a:
            a += d
            if c < a % b:
                print("No")
                break
            a %= b
        else:
            print("Yes")

Submission status: Time Limit Exceeded

Solution code:
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]
    cnt = 0
    while 1 :
        if c[i][0] < c[i][1]:
            print("No")
            break; 
        if c[i][3] < c[i][1]:
            print("No")
            break;            
        if cnt == c[i][1]:
            print("Yes")
            break;
        if c[i][2] < mem1 < c[i][1]:
            print("No")
            break;    
        cnt += 1
        mem1 += mem2