TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A,B,C,D = map(int,input().split())
X = max(C,D)
Y = min(C,D)
def gcd(a,b):
  while b!= 0:
    a,b = b,a%b
  return a
l = C*D/ gcd(X,Y)
def f(x):
  return x - (x//C + x//D - x//l)
ans = f(B) - f(A-1)
print(ans)

A,B,C,D = map(int,input().split())
X = max(C,D)
Y = min(C,D)
def gcd(a,b):
  while b!= 0:
    a,b = b,a%b
  return a
l = int(C*D/ gcd(X,Y))
def f(x):
  return x - (x//C + x//D - x//l)
ans = f(B) - f(A-1)
print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A, B, C, D = map(int, input().split())

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

a, b = map(int, input().split())

print(a*b // gcd(a, b))

ans_c = (B - A) // C
ans_d = (B - A) // D
i = (B - A) // (C * D // gcd(C, D))

print(B - A - ans_c - ans_d + i)

A, B, C, D = map(int, input().split())

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

G = C * D // gcd(C, D)

ans_b = B - B//C - B//D + B//G
ans_a = A - A//C - A//D + A//G

print(ans_b - ans_a + 1)

A, B, C, D = map(int, input().split())

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

a, b = map(int, input().split())

ans_c = (B - A) // C
ans_d = (B - A) // D
i = (B - A) // (C * D // gcd(C, D))

print(B - A - ans_c - ans_d + i)

A, B, C, D = map(int, input().split())

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

G = C * D // gcd(C, D)

ans_b = B - B//C - B//D + B//G
ans_a = A - 1 - (A-1)//C - (A-1)//D + (A-1)//G

print(ans_b - ans_a)

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A,B,C,D=map(int,input().split())
if C<D:
  c=C
  d=D
else:
  c=D
  d=C
while d%c!=0:
  c,d=d%c,c

out=B//C-(A-1)//C+B//D-(A-1)//D-B//(C*D/c)+(A-1)//(C*D/c)
ans=B-A-out+1

print(ans)


A,B,C,D=map(int,input().split())
if C>D:
  c=D
  d=C
else:
  c=C
  d=D
  
f=B//d
g=(A-1)//d
h=B//c
i=(A-1)//c
  
while c:
  c,d=d%c,c
j=C*D//d
k=B//j
l=(A-1)//j
print(B-A+1-(f-g+h-i-k+l))




Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b / gcd(a,b)
a,b,c,d = map(int,input().split())
canC = int(b//c) -int((a-1)//c)
canD = int(b//d) - int((a-1)//d))
dbCD = int(b//lcm(c,d)) -int((a-1)//lcm(c,d))
print((b-a+1) -canC - canD + dbCD)


#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b / gcd(a,b)
a,b,c,d = map(int,input().split())
canC = int(b//c) -int((a-1)//c)
canD = int(b//d) - int((a-1)//d)
dbCD = int(b//lcm(c,d)) -int((a-1)//lcm(c,d))
print((b-a+1) -canC - canD + dbCD-1)


#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b // gcd(a,b)
a,b,c,d = map(int,input().split())
canC = int(b//c) -int((a-1)//c)
canD = int(b//d) - int((a-1)//d)
dbCD = int(b//lcm(c,d)) -int((a-1)//lcm(c,d))
print((b-a+1) -canC - canD + dbCD)


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a*b//gcd(a,b)

a,b,c,d = map(int,input().split())
div = lcm(c,d)

x_div = a//div
y_div = b//div
x_c = a//c
y_c = b//c
x_d = a//d
y_d = b//d
print(b-a+1+(y_div-x_div)-(y_c-x_c)-(y_d-x_d))

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

def lcm(a,b):
    return a*b//gcd(a,b)

a,b,c,d = map(int,input().split())
div = lcm(d,c)

if div <= b:
    x_div = a//div
    y_div = b//div
    if a%div == 0:
        x_div -= 1
else:
    x_div = 0
    y_div = 0
x_c = a//c
if a%c == 0:
    x_c -=1
y_c = b//c
x_d = a//d
if a%d == 0:
    x_d -= 1
y_d = b//d
print(b-a+1+(y_div-x_div)-(y_c-x_c)-(y_d-x_d))

Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def gcd(a, b):
    if a < b:
        a, b = b, a
    return b if a%b == 0 else gcd(b, a%b)

def solve(a, b, c, d):
    ans = b - a + 1
    for p in [c, d]:
        ans -= b // p - (a-1) // p
    for p in [c*d//gcd(c,d)]:
        ans += b // p - (a-1) // p
    return ans

print(24, 18, gcd(24, 18))

a, b, c, d = map(int, input().split())
print(solve(a, b, c, d))

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

def solve(a, b, c, d):
    ans = b - a + 1
    for p in [c, d]:
        ans -= b // p - (a-1) // p
    for p in [c*d//gcd(c,d)]:
        ans += b // p - (a-1) // p
    return ans

a, b, c, d = map(int, input().split())
print(solve(a, b, c, d))

Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A, B, C, D = [int(e) for e in input().split()]

import math
G = math.gcd(C, D)

A_B = []
for AB in [A-1, B]:
  AB_c = AB // C
  AB_d = AB // D
  AB_g = AB // G
  A_B.append(AB_c + AB_d - AB_g)
can_divide = A_B[1] - A_B[0]
ans = (B - (A-1)) - can_divide
print(ans)

A, B, C, D = [int(e) for e in input().split()]
E = max(C, D)
F = min(C, D)

mod = 1
while mod > 0:
  mod = E % F
  if mod == 0:
    break
  else:
    E = F
    F = mod
G = C*D // F

A_B = []
for AB in [A-1, B]:
  AB_c = AB // C
  AB_d = AB // D
  AB_g = AB // G
  A_B.append(AB_c + AB_d - AB_g)
can_divide = A_B[1] - A_B[0]
ans = (B - (A-1)) - can_divide
print(ans)

Verdicts: Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
a, b, c, d  = map(int,input().split())
import math
def divbyk(k):
    return    b//k-(a-1)//k

def gcd(x,y):
    n = min(x,y)
    m = max(x,y)
    if n == 0:
        return m
    else:
        return gcd(n,m-(m//n)*n)

ans = b-a+1-divbyk(c)-divbyk(d)+divbyk(c*d/gcd(c,d))
print(ans)

a, b, c, d  = map(int,input().split())
def divbyk(k):
    return    b//k-(a-1)//k

def gcd(x,y):
    n = min(x,y)
    m = max(x,y)
    if n == 0:
        return m
    else:
        return round(gcd(n,m-(m//n)*n))

ans = b-(a-1) - divbyk(c) - divbyk(d) + divbyk(c*d//gcd(c,d))
print(int(ans))

Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
import numpy as np

a, b, c, d = [int(i) for i in input().split()]

num = np.arange(b - a + 1) + a
print(num[num % (c * d) != 0].shape[0])

import numpy as np
import math

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

a, b, c, d = [int(i) for i in input().split()]
#
#num = np.arange(b - a + 1) + a
#
#if b < c and b < d:
#    print('0')
#    exit(0)
#
#m = min(c, d)
#div = max(c, d)
#tmp = []
#div = num[0] // div + div
#index = 0
#while True:
#    if n[index] % div != 0:
#        if index + div >
#        tmp += range(n[index], n[index])
#        index += 1
#    else:
#        index += div
#
#tmp = np.array(tmp)
#print(tmp[tmp % m == 0].shape[0])


size = b - a + 1
cd = int(c * d // gcd(c, d))
c_num_a = a // c
d_num_a = a // d
cd_num_a = a // cd
c_num_b = b // c
d_num_b = b // d
cd_num_b = b // cd

c_num = c_num_b - c_num_a
d_num = d_num_b - d_num_a
cd_num = cd_num_b - cd_num_a

#if a % c == 0:

#if a % d == 0:


print(size - c_num - d_num + cd_num)

import numpy as np
import math

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

a, b, c, d = [int(i) for i in input().split()]
#
#num = np.arange(b - a + 1) + a
#
#if b < c and b < d:
#    print('0')
#    exit(0)
#
#m = min(c, d)
#div = max(c, d)
#tmp = []
#div = num[0] // div + div
#index = 0
#while True:
#    if n[index] % div != 0:
#        if index + div >
#        tmp += range(n[index], n[index])
#        index += 1
#    else:
#        index += div
#
#tmp = np.array(tmp)
#print(tmp[tmp % m == 0].shape[0])


size = b - a + 1
cd = int(c * d // gcd(c, d))
c_num_a = a // c
d_num_a = a // d
cd_num_a = a // cd
c_num_b = b // c
d_num_b = b // d
cd_num_b = b // cd

c_num = c_num_b - c_num_a
d_num = d_num_b - d_num_a
cd_num = cd_num_b - cd_num_a

if a % c == 0:
    c_num += 1
if a % d == 0:
    d_num += 1
if a % cd == 0:
    cd_num += 1

print(size - c_num - d_num + cd_num)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A, B, C, D = [int(_) for _ in input().split()]

import math
def dvi_num(b, c):
    return math.floor(b / c)

def lcm(a, b):
    return a * b / math.gcd(a, b)

def dvi_num2(b, c, d):
    return b - dvi_num(b,c) - dvi_num(b,d) + dvi_num(b, lcm(c, d))

ans = dvi_num2(B, C, D) - dvi_num2(A - 1, C, D)
print([dvi_num2(B, C, D), dvi_num2(A - 1, C, D)])

print(ans)

A, B, C, D = [int(_) for _ in input().split()]

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

def lcm(a, b):
    return a * b // gcd(a, b)

def dvi_num2(b, c, d):
    return b - b // c - b //d + b // lcm(c, d)

ans = dvi_num2(B, C, D) - dvi_num2(A - 1, C, D)
print(int(ans))

Verdicts: Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
import math

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def solve():
    a, b, c, d = [int(i) for i in input().split()]

    ab = b - a + 1
    e = c * d / gcd(c, d)

    div = math.floor(ab / c) + math.floor(ab / d) - math.floor(ab / e)

    print(ab - div - 1)

    # 532105071133627368
    # 532105071133627369


if __name__ == '__main__':
    solve()



def gcd(x, y):
    
    if y == 0:
        return x
    return gcd(y, x % y)


def lcm(x, y):
    """Lowest Common Multiple O(min(x,y,))"""
    return x * y // gcd(x, y)


def div_count(x, l, r):
    
    return r // x - (l - 1) // x



a, b, c, d = [int(i) for i in input().split()]

# solve
div_cd = div_count(c, a, b) + div_count(d, a, b) - div_count(lcm(c, d), a, b)

print(b - a + 1 - div_cd)


Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def gcd(a,b):
  while b:
    a,b = b,a%b
  return a

a,b,c,d=map(int,input().split())
al = b-a+1

x = int(b/c) -int((a-1)/c)
y = int(b/d) -int((a-1)/d)
lcm_xy = int(c*d/math.gcd(c,d))
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)

print(al-(x+y-xy))

import math
a,b,c,d=map(int,input().split())
al = b-a+1

x = int(b/c)
y = int(b/d)
lcm_xy = int(c*d/math.gcd(c,d))
xy = int(b/lcm_xy)
bb = x+y-xy

x = int(a/c)
y = int(a/d)
xy = int(a/lcm_xy)
aa = x+y-xy
print(al - (bb -aa))

import math

al = b-a+1

x = int(b/c) -int((a-1)/c)

y = int(b/d) -int((a-1)/d)

lcm_xy = int(a*b/math.gcd(a,b))
で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

import math
a,b,c,d=map(int,input().split())
al = b-a+1

x = int(b/c) -int((a-1)/c)

y = int(b/d) -int((a-1)/d)

lcm_xy = int(c*d/gcd(c,d))
で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

import math

al = b-a+1

x = int(b/c) -int((a-1)/c)

y = int(b/d) -int((a-1)/d)

lcm_xy = int(c*d/math.gcd(c,d))
で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

a,b,c,d=map(int,input().split())
al = b-a+1

x = int(b/c) -int((a-1)/c)

y = int(b/d) -int((a-1)/d)

lcm_xy = int(c*d/math.gcd(c,d))
で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

import math
a,b,c,d=map(int,input().split())
al = b-a+1

x = int(b/c) -int((a-1)/c)

y = int(b/d) -int((a-1)/d)

lcm_xy = int(c*d/math.gcd(c,d))
で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

import math

al = b-a+1

x = int(b/c) -int((a-1)/c)

y = int(b/d) -int((a-1)/d)

lcm_xy = int(c*d/math.gcd(c,d))
で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
print(x,y,xy,al)
print(al-(x+y-xy))

a,b,c,d = map(int,input().split())

a_c = (a-1)//c
a_d = (a-1)//d
a_cd = (a-1)//(c*d//gcd(c,d))

b_c = b//c
b_d = b//d
b_cd = b//(c*d//gcd(c,d))

bb = b - (b_c + b_d - b_cd) 
aa = (a-1) - (a_c + a_d - a_cd)

print(bb - aa)

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

a,b,c,d = map(int,input().split())

a_c = (a-1)//c
a_d = (a-1)//d
a_cd = (a-1)//(c*d//gcd(c,d))

b_c = b//c
b_d = b//d
b_cd = b//(c*d//gcd(c,d))

bb = b - (b_c + b_d - b_cd) 
aa = (a-1) - (a_c + a_d - a_cd)

print(bb - aa)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
from fraction import lcm

a,b,c,d = map(int,input().split())
a-=1
print(b//c+b//d-a//c-a//d-b//(c*d/lcm(c,d)))


import sys
import bisect

sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
def gcd(a,b):
    r = a%b;
    while r > 0:
        a = b
        b = r
        r = a%b
    return b
def lcm(a,b):
    return a*b//gcd(a,b)
def main():
    a,b,c,d = map(int,read().split())
    acnum = (a-1)//c
    bcnum = (b)//c
    adnum = (a-1)//d
    bdnum = (b)//d
    acdnum = (a-1)//(lcm(c,d))
    bcdnum = (b)//(lcm(c,d))

    print((b-a+1)-(bcnum-acnum)-(bdnum-adnum) + (bcdnum-acdnum))
if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def unchi(x,m,n):
  r=x//m+x//n-x//(m＊n)
  return r
a,b,c,d=(int(i) for i in input().split())
print(unchi(b,c,d)-unchi(a,c,d))

def unchi(x,m,n):
  a=x//m+x//n-x//(m＊n)
  return a
a,b,c,d=(int(i) for i in input().split())
print(unchi(b,c,d)-unchi(a,c,d))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def unchi(x,m,n):
  r=x//m+x//n-x//(m*n//(gcd(m,n)))
  return r
a,b,c,d=(int(i) for i in input().split())
print(b-a+1-(unchi(b,c,d)-unchi(a-1,c,d)))

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def lcm(a,b):
    return a*b//gcd(a,b)

def su(a,b,c,d):
    count = 0
    for _ in range(a//c, (b+1)//c):
        count += 1
    for _ in range(a//d, (b+1)//d):
        count += 1
    for _ in range(a//lcm(c,d), (b+1)//lcm(c,d)):
        count -= 1

    print(b+1-a-count)
    
def main():
    a,b,c,d = map(int,input().split())
    su(a,b,c,d)
    
if __name__ == '__main__':
    main()

a,b,c,d = map(int,input().split())

def lcm(a,b):
    return a*b//gcd(a,b)

count = 0
for _ in range(a//c, (b+1)//c):
    count += 1

for _ in range(a//d, (b+1)//d):
    count += 1
for _ in range(a//lcm(c,d), (b+1)//lcm(c,d)):
    count -= 1

print(b+1-a-count)

def lcm(a,b):
    ab = a*b
    while b != 0:
        a, b = b, a%b
    return ab //a

def su(n,c,d):
    return n - n//c - n//d + n//lcm(c,d)
    
def main():
    a,b,c,d = map(int,input().split())
    print(su(b,c,d) - su(a-1,c,d))
    
if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b,c,d= map(int, input().split())







bsep = (b // c) + (b // d) - (b // lem(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lem(c, d)

ans = total - bsep + asep
print(ans)


import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A, B, C, D = map(int, input().split())


x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)


y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)


z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))



not_d = B - (A+1) - (x + y - z)
print(not_d)


import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


a, b, c, d = map(int, input().split())




bsep = (b // c) + (b // d) - (b // lcm(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)

ans = b - (a+1) - bsep + asep
print(ans)


import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


A, B, C, D = map(int, input().split())


x1 = (A-1) // C
x2 = B // C
x = x2 - x1
#print("x:", x)


y1 = (A-1) // D
y2 = B // D
y = y2 - y1
#print("y", y)


z1 = (A-1) // lcm(C, D)
z2 = B // lcm(C, D)
z = z2 - z1
#print("lcm:{}".format(lcm(C, D)))



not_d = B - (A+1) - (x + y - z)
print(int(not_d))


import math


def lem(A, B):
    AB = A * B
    while B != 0:
        A, B = B, A % B
    return AB // A


a, b, c, d = map(int, input().split())


bsep = (b // c) + (b // d) - (b // lem(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lem(c, d)

ans = b - (a+1) - bsep + asep
print(ans)


import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b,c,d= map(int, input().split())







bsep = (b // c) + (b // d) - (b // lem(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lem(c, d)

ans = total - bsep + asep
print(ans)


import math


def lem(A, B):
    AB = A * B
    while B != 0:
        A, B = B, A % B
    return AB // A


a, b, c, d = map(int, input().split())


bsep = (b // c) + (b // d) - (b // lem(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lem(c, d)

ans = b - a+1 - bsep + asep
print(ans)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def input_from_console():
    a, b, c, d = map(int, input().split())
    return a, b, c, d


def solve(a, b, c, d):
    def how_many(to, divide):
        n = to // divide
        return n
    count_by_c = how_many(b, c) - how_many(a - 1, c)
    count_by_d = how_many(b, d) - how_many(a - 1, d)
    count_by_cd = how_many(b, c * d) - how_many(a - 1, c * d)
    print(count_by_c, count_by_d, count_by_cd)
    result = b - a + 1 -(count_by_c + count_by_d - count_by_cd)
    return result

def main():
    a, b, c, d = input_from_console()
    print(solve(a, b, c, d))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


def input_from_console():
    a, b, c, d = map(int, input().split())
    return a, b, c, d

def gcd(i,j):
    i, j = max(i,j), min(i,j)
    if i % j == 0:
        return j
    else:
        while i % j !=0:
            k = i % j
            i, j = j, k
        else:
            return k

def solve(a, b, c, d):
    def how_many(to, divide):
        if to >= divide:
            n = to // divide
        else:
            n = 0
        return n
    count_by_c = how_many(b, c) - how_many(a - 1, c)
    count_by_d = how_many(b, d) - how_many(a - 1, d)
    # print('gcd', int(c*d / math.gcd(c,d)))
    count_by_cd = how_many(b, int(c*d / gcd(c,d))) - how_many(a - 1, int(c*d / gcd(c,d)))
    result = b - a + 1 - (count_by_c + count_by_d - count_by_cd)
    # print(count_by_c,  count_by_d, count_by_cd)

    # print(result)
    return result

def main():
    a, b, c, d = input_from_console()
    print(solve(a, b, c, d))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()


Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def lcm(a,b):
    return int(a*b/gcd(a,b))

def div(a,b,num):
    x = num/b
    sub = num%b
    if (a-1)/b != (a+sub)/b:
        x += 1
    return x

a,b,c,d = map(int,input().split())

num = b-a+1
numc = int(div(a,c,num))
numd = int(div(a,d,num))
numl = int(div(a,lcm(c,d),num))
num = num - numc - numd + numl

print(num)


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

def lcm(a,b):
    return int(a*b//gcd(a,b))

def div(x,c,d):
    return x - x//c - x//d + x//lcm(c,d)


a,b,c,d = map(int,input().split())

a = div(a-1,c,d)
b = div(b,c,d)
num = b-a

print(num)


Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
l=[]
for i in range(1,n+1):
  l.append(abs(l-1+i))
mi=l.index(min(l))
print(n*(l-1)+sum(range(1,n+1))-l-mi)

import math
a,b,c,d=map(int,input().split())
x=b//c-a//c
y=b//d-a//d
g=math.gcd(c,d)
l=c*d//g
z=b//l-a//l
print(b-a+1-x-y+z)

import math
a,b,c,d=map(int,input().split())
x=b//c-(a-1)//c
y=b//d-(a-1)//d
g=math.gcd(c,d)
l=c*d//g
z=b//l-(a-1)//l
print(b-a+1-x-y+z)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
import math
a,b,c,d = map(int, input().split())
cd = math.gcd(cd)
 
def f(x,y,div):
  return int(max(x,y)/div) - int((min(x,y)-1) / div)
print(a-b+1- f(a,b,c) - f(a,b,d) + f(a,b,cd))

import math
a,b,c,d = map(int, input().split())
cd = gcd(cd)

def f(x,y,div):
  return int(max(x,y)/div) - int((min(x,y)-1) / div)
print(a-b+1- f(a,b,c) - f(a,b,d) + f(a,b,cd))

import math
a,b,c,d = map(int, input().split())
cd = math.gcd(c, d)
 
def f(x,y,div):
  return int(max(x,y)/div) - int((min(x,y)-1) / div)
print(a-b+1- f(a,b,c) - f(a,b,d) + f(a,b,cd))

a, b, c, d = map(int, input().split())
 
def gcd(x, y):
    if y > x:
        return gcd(y, x)
    if x % y == 0:
        return y
    return gcd(y, x%y)
 
cd = c * d // gcd(c, d)
 
b_div = b - b//c - b//d + b//cd
a_div = a-1 - (a-1)//c - (a-1)//d + (a-1)//cd
 
print(b_div - a_div)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
a,b,c,d= map(int,input().split())
def gcd(c,d):
    while d!=0:
        c,d=d,c%d
    return c


def lcm(c,d):
    return c*d//gcd(c,d)

a1=0
a2=0
b1=0
b2=0
e1=0
e2=0


e=(c*d)/gcd(c,d)

if(a-1>=c):
    a1=(a-1)//c
else:
    a1=0

if(b>=c):
    b1=b//c
else:
    b1=0

if(a-1>=d):
    a2=(a-1)//d
else:
    a2=0

if(b>=d):
    b2=b//d
else:
    b2=0

if(a-1>=e):
    e1=(a-1)//e
else:
    e1=0

if(b>=e):
    e2=b//e
else:
    e2=0
        
ans=b-a+1-(b1-a1)-(b2-a2)+(e2-e1)

print(ans)

a,b,c,d= map(int,input().split())
def gcd(c,d):
    while d!=0:
        c,d=d,c%d
    return c


def lcm(c,d):
    return c*d//gcd(c,d)

a1=0
a2=0
b1=0
b2=0
e1=0
e2=0


e=int((c*d)/gcd(c,d))

if(a-1>=c):
    a1=(a-1)//c
else:
    a1=0

if(b>=c):
    b1=b//c
else:
    b1=0

if(a-1>=d):
    a2=(a-1)//d
else:
    a2=0

if(b>=d):
    b2=b//d
else:
    b2=0

if(a-1>=e):
    e1=(a-1)//e
else:
    e1=0

if(b>=e):
    e2=b//e
else:
    e2=0
        
ans=b-a+1-(b1-a1)-(b2-a2)+(e2-e1)

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
from sys import stdin
from fractions import gcd
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d

GCD = gcd(c,d_num)

LCM = d*c/GCD
cd_num = int(b//(LCM)-(a-1)//(LCM))

print(b-a+1-(c_num + d_num - cd_num))

from sys import stdin

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

count = 0
for i in range(a,b+1):
    print(i)
    if(i%c==0 or i%d==0):
        count +=1
    if(i%(c*d)):
        count -=1
print(count)

from sys import stdin




def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)



a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d

LCM = d*c//(gcd(c,d))

ans = b-a+1
ans -= c_num
ans -= d_num
ans += b//LCM-(a-1)//LCM
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A, B, C, D = map(int, input().split())

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

def ans(x):
    return x - (x // C + x // D - x // (C * D / gcd(C, D)))

print(ans(B) - ans(A - 1))

A, B, C, D = map(int, input().split())

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

def ans(x):
    return x - (x // C + x // D - x // (C * D // gcd(C, D)))

print(ans(B) - ans(A - 1))

Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
import math
a,b,c,d=map(int,input())
ans=0
# print(a,b,c,d,b//c,a//c)
ans+=(b//c-a//c+(a%c==0))
# print(ans)
ans+=(b//d-a//d+(a%d==0))
# print(ans)
lcm=c*d//math.gcd(c,d)
ans-=(b//lcm-a//lcm+(a%lcm==0))
print(b-a+1-ans)

import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction


# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)
def G(x,y):
    if(x<y):
        x,y=y,x
    if(y==0):
        return x
    return G(y,x%y)


a,b,c,d=l()
ans=0
# print(a,b,c,d,b//c,a//c)
ans+=(b//c-a//c+(a%c==0))
# print(ans)
ans+=(b//d-a//d+(a%d==0))
# print(ans)
lcm=c*d//G(c,d)
ans-=(b//lcm-a//lcm+(a%lcm==0))
print(b-a+1-ans)

Verdicts: Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
a, b, c, d = map(int, input().split())
ans = b - a
ans += b // c + b // d - b // (c * d)
ans -= a // c + a // d - a // (c * d)
print(ans)

a, b, c, d = map(int, input().split())
ans = b - a
print(ans)
ans -= b // c + b // d - b // (c * d)
print(ans)
ans += a // c + a // d - a // (c * d)
print(ans)

a, b, c, d = map(int, input().split())

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def count(b, c, d):
    return b - b//c - b//d + b//(c * d // gcd(c, d))

print(count(b, c, d) - count(a-1, c, d))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A,B,C,D = map(int, input().split())

nrofC = (B // C) - ((A-1) // C)
print(nrofC)
nrofD = (B // D) - ((A-1) // D)
print(nrofD)
nrofCD = (B // (C*D)) - ((A-1) // (C*D))
print(nrofCD)

print((B-(A-1)) - nrofC - nrofD + nrofCD)


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

A,B,C,D = map(int, input().split())

nrofC = (B // C) - ((A-1) // C)
nrofD = (B // D) - ((A-1) // D)

cdlcm = C * D // gcd(C,D)
nrofCD = (B // cdlcm) - ((A-1) // cdlcm)

print((B-(A-1)) - nrofC - nrofD + nrofCD)


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

A,B,C,D = map(int, input().split())

nrofC = (B // C) - ((A-1) // C)
nrofD = (B // D) - ((A-1) // D)

cdlcm = (C * D) // gcd(D,C)
nrofCD = (B // cdlcm) - ((A-1) // cdlcm)

print((B-(A-1)) - nrofC - nrofD + nrofCD)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def abc():
    from math import ceil
    _a, _b, c, d = map(int, input().split())

    a = min(_a, _b)
    b = max(_a, _b)

    cnt_all = b - a + 1

    l = ceil(a / c)
    r = b // c
    cnt_c = r - l + 1

    l = ceil(a / d)
    r = b // d
    cnt_d = r - l + 1

    cd = lcm(c, d)
    l = ceil(a / cd)
    r = b // cd
    cnt_cd = r - l + 1

    print(cnt_all - (cnt_c + cnt_d - cnt_cd))


abc()


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


def lcm(a, b):
    return a * b // gcd(a, b)


def abc():
    from math import ceil
    a, b, c, d = map(int, input().split())

    cnt_all = b - a + 1

    l = ceil(a / c)
    r = b // c
    cnt_c = r - l + 1

    l = ceil(a / d)
    r = b // d
    cnt_d = r - l + 1

    cd = lcm(c, d)
    l = ceil(a / cd)
    r = b // cd
    cnt_cd = r - l + 1

    ans = cnt_all - (cnt_c + cnt_d - cnt_cd)
    if ans < 0:
        ans = 0
    print(ans)


abc()


Verdicts: Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
print(e)


f=math.ceil(a/c) 
g=math.ceil(b/c) 
h=math.ceil(a/d) 
k=math.ceil(b/d) 
l=math.ceil(a/e)
m=math.ceil(b/e)
x=b-a
y=g-f
z=k-h
w=m-l

print(round(x-y-z+w))

import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
 
 
f=math.ceil(a/c) 
g=math.floor(b/c) 
h=math.ceil(a/d) 
k=math.floor(b/d) 
l=math.ceil(a/e)
m=math.floor(b/e)
x=b-a+1
y=g-f+1
z=k-h+1
w=m-l+1
if e<b:
    print(x-y-z)
else:
    print(x-y-z+w)

import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
 
 
f=math.floor(a/c) 
g=math.floor(b/c) 
h=math.floor(a/d) 
k=math.floor(b/d) 
l=math.floor(a/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(round(x-y-z+w))

import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))
 
 
f=math.floor(a/c) 
g=math.floor(b/c) 
h=math.floor(a/d) 
k=math.floor(b/d) 
l=math.floor(a/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(x-y-z+w)

import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))


f=math.ceil(a/c) 
g=math.floor(b/c) 
h=math.ceil(a/d) 
k=math.floor(b/d) 
l=math.ceil(a/e)
m=math.floor(b/e)
x=b-a+1
y=g-f+1
z=k-h+1
w=m-l+1
if e<b:
    print(x-y-z)
else:
    print(x-y-z+w)

import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = round(c * d / gcd(c, d))

f=(a-1)//c
g=b//c
h=(a-1)//d 
k=b//d
l=(a-1)//e
m=b//e

x=(b-a+1)
y=g-f
z=k-h
w=m-l
print(f,g,h,k,l,m)
print(x-y-z+w)

import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = round(c * d / gcd(c, d))

f=(a-1)//c
g=b//c
h=(a-1)//d 
k=b//d
l=(a-1)//e
m=b//e

x=(b-a+1)
y=g-f
z=k-h
w=m-l

print(x-y-z+w)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def euclid(x, y):
    x_1 = x
    y_1 = y
    a = x_1%y_1
    while a != 0:
        x_1 = y_1
        y_1 = a
        a = x_1%y_1
    return (x * y) / y_1

def dif(x, C, D):
    return x - (x//C) - (x//D) + (x//(euclid(C, D)))

def main():
    A, B, C, D = map(int, input().split())
    return dif(B, C, D) - dif((A-1), C, D)

if __name__ == '__main__':
    print(main())


def euclid(x, y):
    x_1 = x
    y_1 = y
    a = x_1%y_1
    while a != 0:
        x_1 = y_1
        y_1 = a
        a = x_1%y_1
    return (x * y) // y_1


def dif(x, C, D):
    return x - (x//C) - (x//D) + (x//(euclid(C, D)))

def main():
    A, B, C, D = map(int, input().split())
    return dif(B, C, D) - dif((A-1), C, D)

if __name__ == '__main__':
    print(int(main()))

Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)¥


A, B, C, D = map(int, input().split())
cnt = B - A + 1
all_range = B // C + B // D - B // lcm(C , D)
sub_end = A - 1
sub_range = sub_end // C + sub_end // D - sub_end // lcm(C , D)
print(cnt - (all_range - sub_range))

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

def lcm(x, y):
    return (x * y) // gcd(x, y)

A, B, C, D = map(int, input().split())
cnt = B - A + 1
all_range = B // C + B // D - B // lcm(C , D)
sub_end = A - 1
sub_range = sub_end // C + sub_end // D - sub_end // lcm(C , D)
print(cnt - (all_range - sub_range))

Verdicts: Runtime Error

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
from sys import stdin
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
print(b-a+1-((b//c + b//d - b//(c*d)) - (a//c + a//d + a//(c*d))))

from math import gcd

def lcm(x, y):
    return (x * y)//gcd(x, y)

a,b,c,d = map(int,input().split())

cd = lcm(c,d)
ab = b-a+1

print(ab-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//cd-(a-1)//cd))

Verdicts: Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A,B,C,D = map(int,input().split())

cList = []

dList = []

numList = []

supC = (B // C)
infC = (A // C)

supD = (B // D)
infD = (A // D)

for i in range(infC,supC+1):
	cList.append(i * C)

for i in range(infD,supD+1):
	dList.append(i * D)
	
for i in range(A,B+1):
	if i in cList or dList is False:
		numList.append(i)
	

print(len(numList))

A,B,C,D = map(int,input().split())

supC = B // C
supD = B // D
supCD = B // (C * D)

infC = A // C
infD = A // D
infCD = A // (C * D)

num = B - A + 1
num = num - supC - supD + supCD + infC + infD - infCD
print(num)

A,B,C,D = map(int,input().split())

def gcd(m,n):
	while n!=0:
		m,n = n,m % n
	return m

def lcm(m,n):
	return m * n // gcd(m,n)

CD = lcm(C,D)

supC = B // C
supD = B // D
supCD = B // (CD)

infC = A // C
infD = A // D
infCD = A // (CD)

num = B - A + 1
num = num - supC - supD + supCD + infC + infD - infCD
print(num)

A,B,C,D = map(int,input().split())

cList = []

dList = []

numList = []

supC = (B // C)
infC = (A // C) + 1

supD = (B // D)
infD = (A // D) + 1

for i in range(A,B+1):
	numList.append(i)
	
for i in range(infC,supC+1):
	cList.append(i * C)
	
for i in range(infD,supD+1):
	dList.append(i * D)
	
numList = len(set(numList) - set(cList) - set(dList))

print(numList)

A,B,C,D = map(int,input().split())

def gcd(m,n):
	while n!=0:
		m,n = n,m % n
	return m

def lcm(m,n):
	return m * n // gcd(m,n)

CD = lcm(C,D)

supC = B // C
supD = B // D
supCD = B // (CD)

infC = (A-1) // C
infD = (A-1) // D
infCD = (A-1) // (CD)

num = B - A + 1
num = num - supC - supD + supCD + infC + infD - infCD
print(num)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a
    print(gcd(a, b))


def lcm(a, b):
    return a * b // gcd(a, b)
    print(lcm(a, b))


A, B, C, D = map(int, input().split())

c = B // C - A // C
d = B // D - A // D
cd = B // lcm(C, D) - A // lcm(C, D)

num = c + d - cd
ans = B - A - num + 1
print(ans)


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


def lcm(a, b):
    return a * b // gcd(a, b)


A, B, C, D = map(int, input().split())

c = B // C - A // C
d = B // D - A // D
cd = B // lcm(C, D) - A // lcm(C, D)

num = c + d - cd
ans = B - A - num + 1
print(ans)


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


def lcm(a, b):
    return a * b // gcd(a, b)


A, B, C, D = map(int, input().split())

c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
cd = B // lcm(C, D) - (A - 1) // lcm(C, D)

num = c + d - cd
ans = B - A - num + 1
print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Submission attempts (in order):
A, B, C, D = map(int, input().split())

C = min(C, D)
D = max(C, D)

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

lcm = C * D // gcd(D, C)

a = A // C + 1
b = B // C
c = A // D + 1
d = B // D
e = A // lcm + 1
f = B // lcm

single_c, single_d, double = 0, 0, 0

if a <= b:
    single_c = b - a + 1
else:
    single_c = 0

if c <= d:
    single_d = d - c + 1
else:
    single_d = 0

if e <= f:
    double = f - e + 1
else:
    double = 0

print(B - A + 1 - single_c - single_d + double)

A, B, C, D = map(int, input().split())

c1 = min(C, D)
d1 = max(C, D)

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

lcm = c1 * d1 // gcd(d1, c1)

def count(x):
    return B // x - ((A - 1) // x)

s = count(c1)
t = count(d1)
u = count(lcm)
v = count(1)

print(v - s - t + u)

Verdicts: Wrong Answer

Accepted
Problem: Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.  Let the current time be time 0. Kizahashi has N jobs numbered 1 to N.  It takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.  Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.  Can Kizahashi complete all the jobs in time? If he can, print `Yes`; if he cannot, print `No`.

Submission attempts (in order):

N=int(input())
A=[0]*N
B=[0]*N
C=[0]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())
    C[i]=[A[i],B[i]]
C.sort(key=lambda x:(x[1],x[0]))
print(C)
t=0
for i in range(N):
    t+=C[i][0]
    if C[i][1]<t:
        print('No')
        exit()
print('Yes')


N=int(input())
A=[0]*N
B=[0]*N
C=[0]*N
for i in range(N):
    A[i],B[i]=map(int,input().split())
    C[i]=[A[i],B[i]]
C.sort(key=lambda x:(x[1],x[0]))
t=0
for i in range(N):
    t+=C[i][0]
    if C[i][1]<t:
        print('No')
        exit()
print('Yes')

Verdicts: Wrong Answer

Accepted
Problem: Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.  Let the current time be time 0. Kizahashi has N jobs numbered 1 to N.  It takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.  Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.  Can Kizahashi complete all the jobs in time? If he can, print `Yes`; if he cannot, print `No`.

Submission attempts (in order):
n = int(input())

ab = [[0]*2 for i in range(n)]

for i in range(n):
	ab[i][0], ab[i][1] = map(int, input().split())

ab.sort(key=lambda x: x[1])

print(ab)

ws = 0

for i in range(n):
	ws += ab[i][0]
	if ws > ab[i][1]:
		print('No')
		break
else:
	print('Yes')

n = int(input())

ab = [[0]*2 for i in range(n)]

for i in range(n):
	ab[i][0], ab[i][1] = map(int, input().split())

ab.sort(key=lambda x: x[1])

ws = 0

for i in range(n):
	ws += ab[i][0]
	if ws > ab[i][1]:
		print('No')
		break
else:
	print('Yes')

Verdicts: Wrong Answer

Accepted
Problem: Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.  Let the current time be time 0. Kizahashi has N jobs numbered 1 to N.  It takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.  Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.  Can Kizahashi complete all the jobs in time? If he can, print `Yes`; if he cannot, print `No`.

Submission attempts (in order):
N = int(input() )
for i in range(N):
  C[i] = list(map(int, input().split() ) )
 
C.sort(key= lambda s:(s[1],s[0]) )
 
 
judge = "Yes"
time = 0
for i in range(N):
  time += C[i][0]
  if time > C[i][1]:
    judge = "No"
    break
print(judge)

N = int(input() )
for i in range(N):
  C[i] = (map(int, input().split() ) )
 
C.sort(key=lambda s:s[1] )
 
judge = "Yes"
time = 0
for i in range(N):
  time += C[i][0]
  if time > C[i][1]:
    judge = "No"
    break
print(judge)

N = int(input() )

for i in range(N):
  A, B = map(int, input().split() )
  C[i] = [A, B]
C.sort(key=lambda s:s[1] )
 
judge = "Yes"
time = 0
for i in range(N):
  time += C[i][0]
  if time > C[i][1]:
    judge = "No"
    break
print(judge)

N = int(input() )
for i in range(N):
  C[i] = [map(int, input().split() ) ]
 
C.sort(key= lambda s:(s[1],s[0]) )
 
judge = "Yes"
time = 0
for i in range(N):
  time += C[i][0]
  if time > C[i][1]:
    judge = "No"
    break
print(judge)

N = int(input() )
C = []
for i in range(N):
  A, B = map(int, input().split() )
  C.append([A, B])
C.sort(key=lambda s:s[1] )
 
judge = "Yes"
time = 0
for i in range(N):
  time += C[i][0]
  if time > C[i][1]:
    judge = "No"
    break
print(judge)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.  Let the current time be time 0. Kizahashi has N jobs numbered 1 to N.  It takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.  Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.  Can Kizahashi complete all the jobs in time? If he can, print `Yes`; if he cannot, print `No`.

Submission attempts (in order):
import itertools

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

def output_list(v):
    print(' '.join(str(x) for x in v))

def main():
    n = int(input())
    p = []
    for i in range(n):
        a, b = input_ints()
        p.append((b - a, b))
    p.sort()
    t = 0
    for i in range(n):
        if t > p[i][0]:
            print('NO')
            return
        t += p[i][1] - p[i][0]
    print('YES')


if __name__ == '__main__':
    main()


import itertools

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

def output_list(v):
    print(' '.join(str(x) for x in v))

def main():
    n = int(input())
    p = []
    for i in range(n):
        a, b = input_ints()
        p.append((b, a))
    p.sort()
    t = 0
    for i in range(n):
        if t > p[i][0] - p[i][1]:
            print('No')
            return
        t += p[i][1]
    print('Yes')


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: Kizahashi, who was appointed as the administrator of ABC at National Problem Workshop in the Kingdom of AtCoder, got too excited and took on too many jobs.  Let the current time be time 0. Kizahashi has N jobs numbered 1 to N.  It takes A_i units of time for Kizahashi to complete Job i. The deadline for Job i is time B_i, and he must complete the job before or at this time.  Kizahashi cannot work on two or more jobs simultaneously, but when he completes a job, he can start working on another immediately.  Can Kizahashi complete all the jobs in time? If he can, print `Yes`; if he cannot, print `No`.

Submission attempts (in order):
from itertools import accumulate

n = int(input())
a = sorted(tuple(map(int, input().split()))[::-1] for _ in range(n))
c, d = zip(*a)
print('YNEOS'[any(x < y for x, y in zip(c, accumulate(d)))::2])


from operator import itemgetter
from itertools import accumulate

n = int(input())
a = sorted((tuple(map(int, input().split())) for _ in range(n)),
           key=itemgetter(1))
c, d = zip(*a)
print('YNEOS'[any(x > y for x, y in zip(accumulate(c), d))::2])


from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = sorted(tuple(map(int, reversed(input().split())) for _ in range(n)))
c, d = (map(itemgetter(i), a) for i in (0, 1))
print('YNeos'[any(x < y for x, y in zip(c, accumulate(d)))::2])

from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = (tuple(map(int, input().split())) for _ in range(n))
c, d = (map(itemgetter(i), sorted(a, key=itemgetter(1)) for i in (0, 1))
print('YNeos'[any(x > y for x, y in zip(accumulate(c), d))::2])

from operator import itemgetter
from itertools import accumulate
 
n = int(input())
a = (tuple(map(int, input().split())) for _ in range(n))
a = sorted(a, key=itemgetter(1))
c, d = (map(itemgetter(i), a) for i in (0, 1))
print('YNeos'[any(x > y for x, y in zip(accumulate(c), d))::2])

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Accepted