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):
import math
def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)/gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (math.floor((b)/c)-math.floor((a)/c))+(math.floor((b)/d)-math.floor((a)/d))- (math.floor((b)/(lc))-math.floor((a)/(lc)))
	print((b-(a-1))-cnt)
	

main()


# 1 2 3 4 5
# 1 3 3 4 5
# 1 4 3 4 5 


import math
def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)/gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (math.floor((b)/c)-math.floor((a)/c))+(math.floor((b)/d)-math.floor((a)/d))- (math.floor((b)/(lc))-math.floor((a)/(lc)))
	print((b-(a-1))-cnt)
	

main()





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

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (((b)//c)-((a-1)//c))+(((b)//d)-((a-1)//d))- (((b)//(lc))-((a-1)//(lc)))
	print((b-(a-1))-cnt)
	

main()

import math
def gcd(a,b):
	if a==0:
		return b
	else:
		return gcd(b%a,a)
def lcm(a,b):
	return (a*b)//gcd(a,b)

def main():
	a ,b,c,d = map(int,input().split())
	lc = lcm(c,d)
	cnt = (((b)//c)-((a-1)//c))+(((b)//d)-((a-1)//d))- (((b)//(lc))-((a-1)//(lc)))
	print((b-(a-1))-cnt)
	

main()


# 1 2 3 4 5
# 1 3 3 4 5
# 1 4 3 4 5 


Verdicts: 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):
import fractions

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

gcd = int(fractions.gcd(c,d))

cc = (c//gcd * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)
~

import math

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

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

gcd_ = int(gcd(c,d))

cc = (c//gcd_ * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)

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 fractions
A,B,C,D = map(int,input().split())
n = (C * D) // fractions.gcd(C,D)
C_D = B / n
c = B / C
d = B / D
m = c + d - C_D
ans = int((B - A + 1) - m)
print(ans)

import fractions
A,B,C,D = map(int,input().split())
n = C * D / fractions.gcd(C,D)
C_D = (B - A + 1) / n
c = (B - A + 1) / C
d = (B - A + 1) / D
m = c + d - C_D
ans = int((B - A + 1) - m)
print(ans)

A, B, C, D = map(int, input().split())
def gcd(a, b):
  if a % b is 0:
    return b
  return gcd(b, a % b)
 
def solve(n):
  return n - (n // C) - (n // D) + (n // (C * D // gcd(C, D)))
 
print(solve(B) - solve(A - 1))

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):
import math
a,b,c,d = map(int,input().split())
e = int(c*d/math.gcd(c,d))
wa = 0
c_seki = int(b/c)-int((a-1)/c)
d_seki = int(b/d)-int((a-1)/d)
e_seki = int(b/e)-int((a-1)/e)
wa = c_seki+d_seki-e_seki
print(b-a+1-wa,c_seki,d_seki,e_seki)

import math
a,b,c,d = map(int,input().split())
e = c*d//math.gcd(c,d)
wa = 0
c_seki = b//c-(a-1)//c
d_seki = b//d-(a-1)//d
e_seki = b//e-(a-1)//e
wa = c_seki+d_seki-e_seki
print(b-a+1-wa)

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 math import *
from fractions import *
a,b,c,d=map(int,raw_input().split())
lcm=lambda x,y: x*y//gcd(x,y)

print(b-a+1 - ((b-a+1)//c + (b-a+1)//d - (b-a+1)//lcm(c,d)))

import math
from fractions import *
a,b,c,d=map(int,input().split())

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

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    if c != d:
        print ((b-a+1) - (b // c - ceil(a / c) + 1) - (b // d - ceil(a / d) + 1) + (b // lcm(c, d) - ceil(a / lcm(c, d)) + 1))
    else:
        print ((b - a + 1) - f(a, b, c))
else:
    print (0)

from math import *
from fractions import *
a,b,c,d=map(int,input().split())
lcm=lambda x,y: x*y//gcd(x,y)

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    if c != d:
        print (b-a+1) - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d))
    else:
        print (b - a + 1) - f(a, b, c)
else:
    print 0

from math import *
from fractions import *
a,b,c,d=map(int,input().split())

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

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    print ((b-a+1) - (b // c - ceil(a / c) + 1) - (b // d - ceil(a / d) + 1) + (b // lcm(c, d) - ceil(a / lcm(c, d)) + 1))
else:
    print (0)

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):
import math
a, b, c, d = list(map(int, input().split()))

cnt = 0
numc = math.floor(b/c) - math.ceil(a/c) + 1
numd = math.floor(b/d) - math.ceil(a/d) + 1

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

cd = (c*d) // gcd(c, d)
numcd = math.floor(b/cd) - math.ceil(a/cd) + 1

cnt = b - a + 1 - numc - numd + numcd

import math
from decimal import Decimal
a, b, c, d = list(map(int, input().split()))

cnt = 0
numc = b//c - math.ceil(Decimal(a)/Decimal(c)) + 1
numd = b//d - math.ceil(Decimal(a)/Decimal(d)) + 1

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

cd = (c*d) // gcd(c, d)
numcd = b//cd - math.ceil(Decimal(a)/Decimal(cd)) + 1

cnt = b - a + 1 - numc - numd + numcd

print(cnt)

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().split())

E = C*D / math.gcd(C,D)

i = B//C
j = B//D
k = A//C
n = A//D
m = B//E
l = A//E

res = B-(A-1)-(i-k)-(j-n)+(m-l)
print(math.floor(res))

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

E = C*D

i = B//C
j = B//D
k = A//C
l = A//E
n = A//D
m = B//E

res = B-(A-1)-(i-k)-(j-n)+(m-l)
print(math.floor(res))

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

E = C*D // math.gcd(C,D)

i = B//C
j = B//D
k = (A-1)//C
l = (A-1)//E
n = (A-1)//D
m = B//E

res = B-(A-1)-(i-k)-(j-n)+(m-l)
print(res)

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 lcm(a, b):
    if b > a:
        a, b = b, a

    x = a * b
    r = b % a
    while r != 0:
        a = b
        b = r
        r = b % a

    return x / b


A, B, C, D = map(int, input().split())
CD = lcm(D, C)
A -= 1

n = (B // C) + (B // D) - (B // CD)
n -= (A // C) + (A // D) - (A // CD)
print(B - A - n)

def lcm(a, b):
    if b > a:
        a, b = b, a

    x = a * b
    r = b % a
    while r != 0:
        a = b
        b = r
        r = b % a

    return x // b


A, B, C, D = map(int, input().split())
CD = lcm(D, C)
A -= 1

n = (B // C) + (B // D) - (B // CD)
n -= (A // C) + (A // D) - (A // CD)
print(B - A - n)

def lcm(a, b):
    if b > a:
        a, b = b, a

    x = a * b
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b

    return x // b


A, B, C, D = map(int, input().split())
CD = lcm(D, C)
A -= 1

n = (B // C) + (B // D) - (B // CD)
n -= (A // C) + (A // D) - (A // CD)
print(B - A - n)

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):
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D = list(map(int,input().split()))
C_bai = list(range(A-(A%C)+C,B,C+1))
D_bai = list(range(A-(A%D)+D,B,D+1))
E = lcm(C,D)
CD_bai = list(range(A-(A%E)+E,B,E+1))
print(B-A+1-len(C_bai)-len(D_bai)+CD_bai)
    

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

A,B,C,D = list(map(int,input().split()))
num_C_bai = ((B-(B%C) - (A-(A%C)+C)))//C + 1
num_D_bai = ((B-(B%D) - (A-(A%D)+D)))//D + 1
E = lcm(C,D)
num_E_bai = ((B-(B%E) - (A-(A%E)+E)))//E + 1
print(B + 1 - A - num_C_bai - num_D_bai + num_E_bai)


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

A,B,C,D = list(map(int,input().split()))
if A%C == 0:
    num_C_bai = (B-(B%C) - A)//C + 1
else:
    num_C_bai = ((B-(B%C) - (A-(A%C)+C)))//C + 1
    
if A%D == 0:
    num_D_bai = (B-(B%D) - A)//D + 1
else:
    num_D_bai = ((B-(B%D) - (A-(A%D)+D)))//D + 1

E = lcm(C,D)

if A%E == 0:
    num_E_bai = (B-(B%E) - A)//E + 1
else:
    num_E_bai = ((B-(B%E) - (A-(A%E)+E)))//E + 1

print(B + 1 - A - num_C_bai - num_D_bai + num_E_bai)


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

def getDivCount( a, b, x ):
    count=0
    if a==0 :
        count+=1
    count+=b//x-a//x
    return count

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

count = b-a+1
count -= getDivCount(a,b,c)
count -= getDivCount(a,b,d)
count += getDivCount(a,b,c*d//math.gcd(c,d))
print(count)


import math

def getDivCount( a, b, x ):
    count=0
    if a!=0 :
        count+=b//x-(a-1)//x
    else:
        count+=b//x+1
    return count

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

count = b-a+1
count -= getDivCount(a,b,c)
count -= getDivCount(a,b,d)
count += getDivCount(a,b,c*d//math.gcd(c,d))
print(count)


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(m, n):
    while n:
        m, n = n, m % n
    return m


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

b_not_division = B - B//C - B//D + C*D//gcd(C, D)
a_mins_one_not_division = (A-1) - (A-1)//C - (A-1)//D + C*D//gcd(C, D)
print(b_not_division-a_mins_one_not_division)

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


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


b_not_division = B - (B//C + B//D - B//(C*D//gcd(C, D)))


a_minus_one_not_division = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//(C*D)//gcd(C, D))
print(b_not_division-a_minus_one_not_division+1)


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


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


b_not_division = B - (B//C + B//D - B//(C*D/gcd(C, D)))

a_minus_one_not_division = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//(C*D)/gcd(C, D))
print(b_not_division-a_minus_one_not_division)


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


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

b_not_division = B - B//C - B//D + B//((C*D)//gcd(C, D))
a_mins_one_not_division = (A-1) - (A-1)//C - (A-1)//D + (A-1)//((C*D)//gcd(C, D))
print(b_not_division-a_mins_one_not_division)


# b_not_division = B - (B//C + B//D - B//(C*D//gcd(C, D)))

# a_minus_one_not_division = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//(C*D)//gcd(C, D))
# print(b_not_division-a_minus_one_not_division)

Verdicts: 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):
import fractions
def lcm(n,m): return n*m//fractions.gcd(n,m)
A,B,C,D=map(int,input().split())
X=B-A
print((X-((X//C)+(X//D)))+(X//lcm(C,D)))

import fractions
def lcm(n,m): return n*m//fractions.gcd(n,m)
A,B,C,D=map(int,input().split())
print(((B-A)-(((B-A)//C)+((B-A)//D)))+((B-A)//lcm(C,D)))

import fractions
def lcm(n,m): return n*m//fractions.gcd(n,m)
A,B,C,D=map(int,input().split())
X=B-A; c=X//C; d=X//D; l=X//lcm(C,D)
print(X-c-d+l)

import math as m
A,B,C,D=map(int,input().split())
A-=1
g=C*D//m.gcd(C,D)
x=B//C-A//C
y=B//D-A//D
z=B//g-A//g
print(B-A-x-y+z)

Verdicts: 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):
#abc133 c
from fractions import gcd
a,b,c,d=map(int,input().split())


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

e=lcm(c,d) 

def kosu(num):
    z=num
    nc=int(num/c)
    nd=int(num/d)
    ne=int(num/e)
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

print(ans)


#abc133 c
from fractions import gcd
a,b,c,d=map(int,input().split())

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


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

e=lcm(c,d) 

def kosu(num):
    z=num
    nc=num//c)
    nd=num//d)
    ne=num//e
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

print(ans)


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

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


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

e=lcm(c,d) 

def kosu(num):
    z=num
    nc=num//c
    nd=num//d
    ne=num//e
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

print(ans)

Verdicts: 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):
import sys
# input = sys.stdin.readline

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


ans = 0
ans += B // C
ans -= (A - 1) // C
# print("#", ans)
ans += B // D
ans -= (A - 1) // D
# print("#", ans)
#
ans -= B // (C * D)
ans += (A - 1) // (C * D)
# print("#", ans)

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

import sys
# input = sys.stdin.readline

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

def div(a, b):
    return a // b

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

ans = 0
ans += div(B, C)
ans -= div(A - 1, C)
# print("#", ans)
ans += div(B, D)
ans -= div(A - 1, D)
# print("#", ans)
#
E = (C * D) // gcd(C, D)
ans -= div(B, E)
ans += div(A - 1, E)
# print("#", ans)

ans = (B - A + 1) - ans
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):
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
A, B, C, D = map(int, input().split())
X = B//C - A//C
Y = B//D - A//D
E = (C*D)//gcd(C,D)
Z = B//E - A//E
print(B-A-X-Y+Z+1)

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
A, B, C, D = map(int, input().split())
X = B//C - (A-1)//C
Y = B//D - (A-1)//D
E = (C*D)//gcd(C,D)
Z = B//E - (A-1)//E
print(B-A-X-Y+Z+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
def Euclidean(x,y):
    if y == 0:
        return x
    else:
        return Euclidean(y,x%y)

A,B,C,D = [int(x) for x in input().split()]
count = B - A + 1
E = Euclidean(C,D)
F = C*D/E

C_ = math.floor(B/C) - math.ceil(A/C) + 1
D_ = math.floor(B/D) - math.ceil(A/C) + 1
C_and_D = math.floor(B/F) - math.ceil(A/F) + 1
print(count - (C_ + D_ -C_and_D)):

import math
def Euclidean(x,y):
    if y == 0:
        return x
    else:
        return Euclidean(y,x%y)

A,B,C,D = [int(x) for x in input().split()]
count = B - A + 1
E = Euclidean(C,D)
F = C*D/E

C_ = math.floor(B/C) - math.floor(A/C)
D_ = math.floor(B/D) - math.floor(A/D)
C_and_D = math.floor(B/F) - math.floor(A/F)
print(count - (C_ + D_ - C_and_D))

    import math
    def Euclidean(x,y):
        if y == 0:
            return x
        else:
            return Euclidean(y,x%y)
     
    A,B,C,D = [int(x) for x in input().split()]
    count = B - A + 1
    E = Euclidean(C,D)
    F = C*D/E
     
    C_ = math.floor(B/C) - math.floor((A-1)/C)
    D_ = math.floor(B/D) - math.floor((A-1)/D)
    C_and_D = math.floor(B/F) - math.floor((A-1)/F)
    print(count - int(C_ + D_ - C_and_D))

import math
def Euclidean(x,y):
    if y == 0:
        return x
    else:
        return Euclidean(y,x%y)

A,B,C,D = [int(x) for x in input().split()]
count = B - A + 1
E = Euclidean(C,D)
F = int(C*D/E)

C_ = B//C - (A-1)//C
D_ = B//D - (A-1)//D
C_and_D = B//F - (A-1)//F
print(count - (C_ + D_ - C_and_D))


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):
import math

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


C_multiple = B // C - A // C
D_multiple = B // D - A // D 

if A % C == 0:
    C_multiple += 1
if A % D == 0:
    D_multiple += 1
        

CD_gcd = C * D / math.gcd(C,D) 
CD_multiple = B // CD_gcd - A// CD_gcd 
if A % CD_gcd == 0:
    CD_multiple += 1
***
print(C_multiple)
print(D_multiple)
print(CD_gcd)
print(CD_multiple)
***
ans = ( B - A + 1 ) - (C_multiple + D_multiple - CD_multiple)
print(int(ans))

import math

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


C_multiple = B // C - A // C
D_multiple = B // D - A // D 

if A % C == 0:
    C_multiple += 1
if A % D == 0:
    D_multiple += 1
        

CD_gcd = math.gcd(C,D)
CD_multiple = B // CD_gcd - A// CD_gcd 
if A % CD_gcd == 0:
    CD_multiple += 1

ans = ( B - A + 1 ) - (C_multiple + D_multiple - CD_multiple)

print(ans)

import math

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


C_multiple = B // C - A // C
D_multiple = B // D - A // D 

if A % C == 0:
    C_multiple += 1
if A % D == 0:
    D_multiple += 1
        

CD_gcd = C * D // math.gcd(C,D) 
CD_multiple = B // CD_gcd - A// CD_gcd 
if A % CD_gcd == 0:
    CD_multiple += 1



ans = ( B - A + 1 ) - (C_multiple + D_multiple - CD_multiple)
print(int(ans))

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 sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

aa = - ((a-1) // x) + ((a-1) // c) + ((a-1) // d)
bb = - b // x + b // c + b // d
ans = (b-a+1)-(bb-aa)

print(ans)


import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
        sys.exit()
    else:
        print(0)
        sys.exit()

aa = a-1-(a-1)//x + (a-1)//c + (a-1)//d
bb = b-b//x + b//c + b//d
ans = bb-aa

print(ans)


import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

a,b,c,d = I()
x = lcm(c,d)

if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
        sys.exit()
    else:
        print(0)
        sys.exit()

aa = a-1+(a-1)//x - (a-1)//c - (a-1)//d
bb = b+b//x - b//c - b//d
ans = bb-aa

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())
q=[a,b]
for w in range(0,2):
    x=q[w]//c
    y=q[w]//d
    k,j=c,d
    g=c%d
    while g!=0:
        k,j=d,g
        g=k%j
    l=c*d//j
    z=q[w]//l
    q[w]=q[w]-x-y+z
print(int(q[1]-q[0]+1))

a,b,c,d=map(int,input().split())
q=[a,b]
for w in range(0,2):
    x=q[w]//c
    y=q[w]//d
    k,j=c,d
    g=c%d
    while g!=0:
        k,j=d,g
        g=k%j
    l=c*d/j
    z=q[w]//l
    q[w]=q[w]-x-y+z
print(int(q[1]-q[0]+1))

a,b,c,d = map(int, input().split())
e = 0
for l in range(a-1,b+1):
    if l%c != 0 and l%d != 0:
        e += 1

def gcd(a,b):
    while b:a,b=b,a%b
    return a
def lcm(c,d):return c*d//gcd(c,d)
def div(x):
    num=x
    num-=x//C
    num-=x//D
    num+=x//lcm(C,D)
    return num
A,B,C,D=map(int,input().split())
print(div(B)-div(A-1))

Verdicts: 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):
import math
a,b,c,d=input().split(" ")
A=int(a)
B=int(b)
C=int(c)
D=int(d)
def nb_divisers(n,m):
    return n//m
def nb_d_btw(f,g,n):
    if f%n==0:
        print(nb_divisers(g,n)-nb_divisers(f,n)+1)
        return nb_divisers(g,n)-nb_divisers(f,n)+1
    else:
        print(nb_divisers(g,n)-nb_divisers(f,n))
        return nb_divisers(g,n)-nb_divisers(f,n)
def nb_notdivisers_f(a,b,c,d):
    e=int(c*d/math.gcd(c,d))
    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))
print(nb_notdivisers_f(A,B,C,D))

import math
A,B,C,D=(int(x) for x in input().split(" "))
def nb_divisers(n,m):
    return n//m
def nb_d_btw(f,g,n):
    if f%n==0:
        print(nb_divisers(g,n)-nb_divisers(f,n)+1)
        return nb_divisers(g,n)-nb_divisers(f,n)+1
    else:
        print(nb_divisers(g,n)-nb_divisers(f,n))
        return nb_divisers(g,n)-nb_divisers(f,n)
def nb_notdivisers_f(a,b,c,d):
    e=int(c*d/math.gcd(c,d))
    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))
print(nb_notdivisers_f(A,B,C,D))

import fractions
A,B,C,D=(int(x) for x in input().split(" "))
def nb_divisers(n,m):
    return n//m
def nb_d_btw(f,g,n):
    if f%n==0:
        print(nb_divisers(g,n)-nb_divisers(f,n)+1)
        return nb_divisers(g,n)-nb_divisers(f,n)+1
    else:
        print(nb_divisers(g,n)-nb_divisers(f,n))
        return nb_divisers(g,n)-nb_divisers(f,n)
def nb_notdivisers_f(a,b,c,d):
    e=int(c*d/fractions.gcd(c,d))
    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))
print(nb_notdivisers_f(A,B,C,D))


A,B,C,D=(int(x) for x in input().split(" "))
def gcd(x,y): 
  
   while(y): 
        x, y = y, x % y 
  
   return x 
def nb_divisers(n,m):
    return n//m
def nb_d_btw(f,g,n):
    if f%n==0:
        return nb_divisers(g,n)-nb_divisers(f,n)+1
    else:
        return nb_divisers(g,n)-nb_divisers(f,n)
def nb_notdivisers_f(a,b,c,d):
    e=int(c*d/gcd(c,d))
    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))
print(nb_notdivisers_f(A,B,C,D))

Verdicts: Runtime Error

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):
from math import gcd

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

from math import gcd

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

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:
    tmp = a
    a = b
    b = tmp
 
  r = a % b
  while (r!=0): 
    a = b
    b = r
    r = a % b
  return b


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

upperC = int(B / C)
upperD = int(B / D)
lowerC = int(A / C)
lowerD = int(A / D)

numC = upperC - lowerC
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D / gcd
upperL = int(B / lcm)
lowerL = int(A / lcm)
numL = upperL - lowerL

print(str(B - A + 1 - (numC + numD - numL)))




def GCD(a,b):
  if a<b:
    tmp = a
    a = b
    b = tmp
 
  r = a % b
  while (r!=0): 
    a = b
    b = r
    r = a % b
  return b


A,B,C,D = map(int,input().split())
A = A - 1
upperC = int(B // C)
upperD = int(B // D)
lowerC = int(A // C)
lowerD = int(A // D)

numC = upperC - lowerC
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D // gcd
upperL = int(B // lcm)
lowerL = int(A // lcm)
numL = upperL - lowerL

print(str(B - A - (numC + numD - numL)))

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):
    if x==0:return y
    else:return gcd(y%x,x)
def lcm(x,y):
    return x*y//gcd(x,y)
 
a,b,c,d = map(int,input().split())
a -= 1
# print(gcd(c,d),lcm(c,d))
ba = b - b//c - b//d + b//lcm(c,d)
aa = a - a//c - a//d + a//lcm(c,d)
print(ba - aa)

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

def gcd(a,b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b
def fine(a,b,c):
    return 
res = 0
e = (c*d)//gcd(c ,d)
res-= a//c - b//c
print(res)
res-= a//d - b//d
print(res)
res+= a//e - b//e
print(b-a-res+1)
print(a,b,res)



def gcd(x,y):
    if x==0:return y
    else:return gcd(y%x,x)
def lcm(x,y):
    return x*y//gcd(x,y)
 
a,b,c,d = map(int,input().split())
a -= 1
# print(gcd(c,d),lcm(c,d))
ba = b - b//c - b//d + b//lcm(c,d)
aa = a - a//c - a//d + a//lcm(c,d)
print(ba - aa)

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:
    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())
CD = lcm(C, D)

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

c_first = (A-1) // C
c_last = B // C
d_first = (A-1) // D
d_last = B // D
cd_first = (A-1) // CD
cd_last = B // CD

c_count = 0
d_count = 0
cd_count = 0
if c_last != 0:
  c_count = c_last - c_first
if d_last != 0:
  d_count = d_last - d_first
if cd_last != 0:
  cd_count = cd_last - cd_first
    
print(c_first, c_last, d_first, d_last, cd_first, cd_last)
print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))



def gcd(a, b):
  while b:
    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())
CD = lcm(C, D)

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

c_first = (A-1) // C
c_last = B // C
d_first = (A-1) // D
d_last = B // D
cd_first = (A-1) // CD
cd_last = B // CD

c_count = 0
d_count = 0
cd_count = 0
if c_last != 0:
  c_count = c_last - c_first + 1
if d_last != 0:
  d_count = d_last - d_first + 1
if cd_last != 0:
  cd_count = cd_last - cd_first + 1
    
#print(c_first, c_last, d_first, d_last, cd_first, cd_last)
#print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))



def gcd(a, b):
  while b:
    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())
CD = lcm(C, D)

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

c_first = (A-1) // C
c_last = B // C
d_first = (A-1) // D
d_last = B // D
cd_first = (A-1) // CD
cd_last = B // CD

c_count = 0
d_count = 0
cd_count = 0
if c_last != 0:
  c_count = c_last - c_first
if d_last != 0:
  d_count = d_last - d_first
if cd_last != 0:
  cd_count = cd_last - cd_first
    
#print(c_first, c_last, d_first, d_last, cd_first, cd_last)
#print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))



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):
import fractions
a,b,c,d=map(int,input().split())
x=b-(b//c+b//d-b//(c*d/fractions.gcd(c,d)))
y=(a-1)-((a-1)//c+(a-1)//d-(a-1)//(c*d/fractions.gcd(c,d)))

print(int(x-y))

def gcd(a, b):
    while b:
        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())
b_num=b//c + b//d - b//lcm(d,c)
a_num=(a-1)//c + (a-1)//d - (a-1)//lcm(d,c)

print(b-(a-1)-(b_num-a_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):
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def baisu(x,a):
    return int(x//a)
a,b,c,d = map(int,input().split())

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d/gcd(c,d))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d/gcd(c,d))

print(to_a)
print(to_b)


if a%c == 0 or a%d == 0:
    print(int(to_b - to_a))
else:
    print(int(to_b-to_a+1))


def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def baisu(x,a):
    return int(x//a)
a,b,c,d = map(int,input().split())

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d/gcd(c,d))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d/gcd(c,d))

print(to_a)
print(to_b)


if a%c == 0 or a%d == 0:
    print(int(to_b - to_a))
else:
    print(int(to_b-to_a+1))


def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def baisu(x,a):
    return int(x//a)
a,b,c,d = map(int,input().split())

to_a = a-1 - baisu(a-1,c) - baisu(a-1,d) + baisu(a-1,int(c*d/gcd(c,d)))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,int(c*d/gcd(c,d)))

print(to_b - to_a)



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):
# coding: utf-8
# Your code here!
import math

A,B,C,D=map(int,input().split())
A-=1
print(A)
num1=A-A//C-A//D+(A//(C*D//math.gcd(C, D)))
num2=B-B//C-B//D+(B//(C*D//math.gcd(C, D)))

print(num1)
print(num2)

print(num2-num1)

# coding: utf-8
# Your code here!
A,B,C,D=map(int,input().split())
A-=1

def gcd(a,b):
    ans=1
    for i in range(1,int(min(a,b)**0.5)+1):
        
        if a%i==0 and b%i==0:
            ans=max(ans,i)
        temp=min(a,b)//i
        if a%temp==0 and b%temp==0:
            ans=max(ans,temp)
    return ans

num1=A-A//C-A//D+(A//(C*D//gcd(C, D)))
num2=B-B//C-B//D+(B//(C*D//gcd(C, D)))

print(num2-num1)

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 fractions
import math

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

C_ = len(range(math.ceil(A/C)*C,B+1,C))
D_ = len(range(math.ceil(A/D)*D,B+1,D))
CD = (C*D) // fractions.gcd(C, D)
CD_ = len(range(math.ceil(A/CD)*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)




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


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

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

C_ = len(range(A//C*C if A//C*C ==A else A//C*(C+1),B+1,C))
D_ = len(range(A//D*D if A//D*D ==A else A//D*(D+1),B+1,D))
CD = lcm(C, D)
CD_ = len(range(A//CD*CD if A//CD*CD ==A else A//CD*(CD+1),B+1,CD))

print(B-A+1-C_-D_+CD_)

import math


def gcd(a, b):
    while b:
        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_ = len(range(A//C*C if A%C==0 else (A//C+1)*C,B+1,C))
D_ = len(range(A//D*D if A%D==0 else (A//D+1)*D,B+1,D))
CD = lcm(C,D)
CD_ = len(range(A//CD*CD if A%CD==0 else (A//CD+1)*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)

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 gcd(m, n):
  while n:
    m, n = n, m % n
  return m

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

A, B, C, D = list(map(int, input().split()))
lcm = lcm(max(C, D), min(C, D))
print((B - A + 1) - (B // C - A // C) - (B // D - A // D) + (B // lcm - A // lcm))

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

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

def count(a, b, q):
  _a = min(a, b)
  _b = max(a, b)
  if a % q == 0:
    return _b // q - _a // q + 1
  else:
    return _b // q - _a // q

A, B, C, D = list(map(int, input().split()))
lcm = lcm(max(C, D), min(C, D))
print((B - A + 1) - count(A, B, C) - count(A, B, D) + count(A, B, lcm))

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 b == 0:
        return a
    return gcd(b, a % b)

def lcm(a, b):
    return a * b / gcd(a, b)
A, B, C, D = map(int, input().split())
diff = B - A
ret = 0
if C == 1 or D == 1:
    print(0)
else:
    ret += diff // C
    if A % C == 0:
        ret += 1
    ret += diff // D
    if A % D == 0:
        ret += 1
    a = diff // int(lcm(C, D))
    print(diff-ret+a)
    

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

def lcm(a, b):
    return a * b / gcd(a, b)
A, B, C, D = map(int, input().split())
diff = B - A
ret = 0
if C == 1 or D == 1:
    print(0)
else:
    ret += diff // C
    if A % C == 0:
        ret += 1
    ret += diff // D
    if B % D == 0:
        ret += 1
    a = diff // int(lcm(C, D))
    print(diff-ret+a)
    

A, B, C, D = map(int, input().split())
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)

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

def calc(n, c, d):
    lcm_num = n // lcm(c, d)
    c_num = n // c
    d_num = n // d
    return n - c_num - d_num + lcm_num

ret = calc(B, C, D) - calc(A-1, C, D)
print(ret)

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):
import math

print("test")

a,b,c,d=map(int,input().split())
def lcm(x,y):
    return (x*y)//math.gcd(x,y)
lm=lcm(c,d)
print(lm)

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

a,b,c,d=map(int,input().split())
cn1=0
cn2=0
cn3=0
an1=0
an2=0
an3=0
cnt=0
ans=0
lm=(c*d)//gcd(c,d)


cn1=b//c
cn2=b//d
cn3=b//lm

an1=(a-1)//c
an2=(a-1)//d
an3=(a-1)//lm

cn1=cn1-an1
cn2=cn2-an2
cn3=cn3-an3

cnt=cn1+cn2-cn3
ans=b-a-cnt+1

print(ans)


Verdicts: 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())

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

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

b_num = b - b//c - b//d + b//lcm
a_num = a - a//c - a//d + a//lcm

ans = b_num - a_num + 1

print(ans)


import math

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

lcm = c*d//math.gcd(c,d)

b_num = b - b//c - b//d + b//lcm
a_num = a - a//c - a//d + a//lcm

ans = b_num - a_num + 1

print(int(ans))

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

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

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

b_num = b - b//c - b//d + b//lcm
a_num = a - a//c - a//d + a//lcm

if b_num == 0 and a_num == 0:
    ans = 0
else:
    ans = b_num - a_num + 1

print(ans)

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

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

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

b_num = b - b//c - b//d + b//lcm
a_num = a - a//c - a//d + a//lcm

if a_num == 0:
    ans = b_num
else:
    ans = b_num - a_num + 1

print(ans)

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

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

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

b_num = b - b//c - b//d + b//lcm
a_num = (a-1) - (a-1)//c - (a-1)//d + (a-1)//lcm


ans = b_num - a_num

print(ans)

Verdicts: Wrong Answer

Runtime Error

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:
    a, b = b, a % b
  return a

A, B, C, D = map(int, input().split())
L = C * D // gcd(C, D)
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
l = B // L - (A - 1) // L

print(A - B + 1 - c - d + l)

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

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

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

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

A, B, C, D = map(int, input().split())
L = C * D // gcd(C, D)
c = B // C - (A - 1) // C
d = B // D - (A - 1) // D
l = B // L - (A - 1) // L

print(B - A + 1 - c - d + l)

Verdicts: 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 d>c:
  euclid2,euclid1=c,d
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
if c>d:
  euclid2,euclid1=d,c
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
  
c1=(a-1)//c
c2=(b-c1*c)//c+1
d1=(a-1)//d+1
d2=(b-d1*d)//d+1
cd1=(a-1)//cd+1
cd2=(b-cd1*cd)//(c*d)+1  
print(b-a+1-c2-d2+max(0,cd2))

a,b,c,d=map(int,input().split())
euclid2,euclid1=c,d
e1,e2=euclid1,euclid2
while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1

c1=(a-1)//c
c2=(b-c1*c)//c+1
d1=(a-1)//d+1
d2=(b-d1*d)//d+1
cd1=(a-1)//cd+1
cd2=(b-cd1*cd)//(c*d)+1  
print(b-a+1-c2-d2+max(0,cd2))
  

a,b,c,d=map(int,input().split())
euclid2,euclid1=c,d
e1,e2=euclid1,euclid2
while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
if c>b and d>b:
  print(b-a+1)
  exit()
elif c>b:
  d1=a//d+1
  print(b-a-(b-d1*d)//d)
  exit()
elif d>b:
  c1=a//c+1
  print(b-a-(b-c1*c)//c)
  exit()
else :
  c1=a//c+1
  c2=(b-c1*c)//c+1
  d1=a//d+1
  d2=(b-d1*d)//d+1
  cd1=a//cd+1
  cd2=(b-cd1*cd)//(c*d)+1
  print(b-a+1-c2-d2+cd2)
  


a,b,c,d=map(int,input().split())
if c>b and d>b:
  print(b-a+1)
  exit()
elif c>b:
  for i in range(b):
    if d*i>=a:
      d1=i*d
  print(b-a-(b-d1)//d)
  exit()
elif d>b:
  for i in range(b):
    if c*i>=a:
      c1=i*c
  print(b-a-(b-c1)//c)
  exit()
else :
  clst=[c*i for i in range(a//c+1,(b-c*i)//c+i+1)]    
  dlst=[d*i for i in range(a//c+1,(b-d*i)//d+i+1)]
  lst=set(clst+dlst)
  print(b-a+1-len(lst))
  


a,b,c,d=map(int,input().split())
if d>c:
  euclid2,euclid1=c,d
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
else:
  euclid2,euclid1=d,c
  e1,e2=euclid1,euclid2
  while not euclid2==0:
    euclid1=euclid1%euclid2
    euclid1,euclid2=euclid2,euclid1
    cd=c*d//euclid1
  
c1=(a-1)//c+1
c2=(b-c1*c)//c+1
d1=(a-1)//d+1
d2=(b-d1*d)//d+1
cd1=(a-1)//cd+1
cd2=(b-cd1*cd)//cd+1  
print(b-a+1-c2-d2+cd2)


Verdicts: Runtime Error

Wrong Answer

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):
import fractions
a,b,c,d = map(int,input().split())
li=[]
for i in [a-1,b]:
    bc = i//c
    bd = i//d
    gc = c*d / fractions.gcd(c,d)
    cd = i//gc
    li.append(i-(bc+bd-cd))
print(int(li[1]-li[0]))

from fractions import gcd
a,b,c,d = map(int,input().split())
li=[]
for i in [a-1,b]:
    bc = i//c
    bd = i//d
    gc = c*d / gcd(c,d)
    cd = i//gc
    li.append(i-(bc+bd-cd))
print(int(li[1]-li[0]))

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())
li=[]
gc = lcm(c,d)
for i in [a-1,b]:
    bc = i//c
    bd = i//d
    cd = i//gc
    li.append(i-(bc+bd-cd))
print(int(li[1]-li[0]))

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):
import math
import fractions
import numpy

np.set_printoptions(suppress=True)


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

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

ans = int( B // C - (A-1) // C ) + int(B // D - (A-1) // D) - int(B // G - (A-1) // G)

print (B - A + 1 - ans)


import math
import fractions


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

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

ans = int(( B // C - (A-1) // C ) + (B // D - (A-1) // D) - (B // G - (A-1) // G))

print (B - A + 1 - ans)


from decimal import Decimal

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


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

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

#print('{:.100g}'.format(G))

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

print ('{:.100g}'.format(B - A + 1 - ans))


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
def lcm(a,b):
    A,B=a,b
    while b!=0:
        a,b=b,a%b
    return A*B/a

def count(a,b,c):
    return b//c-(a-1)//c

A,B,C,D=map(int,input().split())
C_count = count(A,B,C)
D_count = count(A,B,D)
CD_count = count(A,B,lcm(C,D))
ans = B - (A - 1) - (C_count + D_count - CD_count)
print("{}".format(ans))


import math
def lcm(a,b):
    A,B=a,b
    while b!=0:
        a,b=b,a%b
    return A*B//a
 
def count(a,b,c):
    return math.floor(b/c)-math.floor((a-1)/c)
 
A,B,C,D=map(int,input().split())
C_count = count(A,B,C)
D_count = count(A,B,D)
CD_count = count(A,B,lcm(C,D))
ans = B - (A - 1) - (C_count + D_count - CD_count)

import math
def lcm(a,b):
    A,B=a,b
    while b!=0:
        a,b=b,a%b
    return A*B//a
 
def count(a,b,c):
    return b//c-(a-1)//c
 
A,B,C,D=map(int,input().split())
C_count = count(A,B,C)
D_count = count(A,B,D)
CD_count = count(A,B,lcm(C,D))
ans = B - (A - 1) - (C_count + D_count - CD_count)
print("{}".format(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):
import fractions

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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    a -= 1
    cnt = b - a
    cnt -= int(b/c) - int(a/c)
    cnt -= int(b/d) - int(a/d)
    l = lcm(c, d)
    cnt += int(b/l) - int(a/l)
    print(cnt)


import math


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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    cnt_ac, cnt_bc = int((a-1)/c), int(b/c)
    cnt_ad, cnt_bd = int((a-1)/d), int(b/d)
    cnt_acd, cnt_bcd = int(a/lcm(c,d)), int(b/lcm(c,d))
    print((cnt_bc-cnt_ac), (cnt_bd-cnt_ad), (cnt_bcd-cnt_acd))
    print((b-a+1) - ((cnt_bc-cnt_ac)+(cnt_bd-cnt_ad)-(cnt_bcd-cnt_acd)))


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


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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    a -= 1
    cnt = b - a
    cnt -= b//c - a//c
    cnt -= b//d - a//d
    l = lcm(c, d)
    cnt += b//l - a//l
    print(cnt)


Verdicts: 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):
# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1 = d if c < d else c
d1 = c if c < d else d
while d1 != 0:
    e = d1
    d1 = c1 % d1
    c1 = e
e = c * d / e
a -= 1
cnt = (b - a) + b // e - a // e - b // c + a // c - b // d + a // d
print(cnt)


# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1, d1 = [d if c < d else c, c if c < d else d]
while d1 > 1:
    e = d1
    d1 = c1 % d1
    c1 = e
e = c * d / e
cnt = (b - a + 1) + int(b / e) - int(a / e) - int(b / c) + int(a / c) - int(b / d) + int(a / d)
print(cnt)


# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1, d1 = [d if c < d else c, c if c < d else d]
while d1 > 0:
    e = d1
    d1 = c1 % d1
    c1 = e
e = c * d / e
print(e)
cnt = (b - a + 1) + int(b / e) - int((a-1) / e) - int(b / c) + int((a-1) / c) - int(b / d) + int((a-1) / d)
print(cnt)


# coding: utf-8
a, b, c, d = [int(i) for i in input().split()]
c1 = d if c < d else c
d1 = c if c < d else d
while d1 != 0:
    e = d1
    d1 = c1 % d1
    c1 = e
e = int((c * d) / e)
a -= 1
cnt = (b - a) + int(b // e) - int(a // e) - int(b // c) + int(a // c) - int(b // d) + int(a // d)
print(cnt)


Verdicts: Wrong Answer

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 = map(int, input().split())

def multiple(X, Y, Z):
    min_z = X // Z + 1
    max_z = Y // Z 
    num_z = max_z - min_z + 1
    return num_z 

def gcd(X, Y):
    while Y!= 0:
        X, Y = Y, X % Y
    return X

if C == 1 or D == 1:
    print(0)
else:
    num_c = multiple(A, B, C)
    print(num_c)
    num_d = multiple(A, B, D)
    print(num_d)
    lcm = int((C * D) / gcd(C, D)) 
    num_lcm = multiple(A, B, lcm)
    print(B - A + 1 - num_c - num_d + num_lcm)


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

def multiple(X, Y, Z):
    
    if X % Z != 0:
        min_z = X // Z + 1
    else:
        min_z = X / Z
    max_z = Y // Z
    num_z = max_z - min_z + 1
    return int(num_z)

def gcd(X, Y):
    while Y!= 0:
        X, Y = Y, X % Y
    return X

if C == 1 or D == 1:
    print(0)
else:
    num_c = multiple(A, B, C)
    num_d = multiple(A, B, D)
    lcm = int((C * D) / gcd(C, D)) 
    num_lcm = multiple(A, B, lcm)
    print(B - A + 1 - num_c - num_d + num_lcm)


Verdicts: Wrong Answer

Accepted