Problem:


Score : 300 points

Problem Statement

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.

Constraints

1\leq A\leq B\leq 10^{18}

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368



Sample input:
4 9 2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
import fractions

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

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

c_divide = (B // C) - ((A - 1) // C)
d_divide = (B // D) - ((A - 1) // D)
cd_divide = (B // lcm(C, D)) - (A // lcm(C, D))
ans = (B - A + 1) - c_divide - d_divide + cd_divide
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc131/tasks/abc131_c
# A~Bと言われたら、0~B と 0~Aの個数で成り立つのではないか？と考える典型問題


def f(n, c, d):
    # nを含んでcでもdでも割り切れる数の個数を返す
    return n // c + n // d - n // (c * d)


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

print((B - A + 1) - (f(B, C, D) - f(A - 1, C, D)))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
mul = C*D
mi = (A-1) // mul
ma = B // mul
mv = ma-mi
ci = (A-1) // C
ca = B // C
cv = ca-ci
di = (A-1) // D
da = B // D
dv = da-di
print(B-A-cv-dv+mv+1)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a < b:
        a, b = b, a
    while  a % b != 0:
        a, b = b, a % b
    return b
a,b,c,d = map(int, input().split())
res = 0
lcm = c*d // gcd(c,d)
divisible = (b//c) - ((a-1)//c) + (b//d) - ((a-1)//d) - (b//lcm) - ((a-1)//lcm)
res = b-a+1 - divisible
print(res)

Submission status: Wrong Answer

Solution code:
import sys
import math
import fractions
def input(): return sys.stdin.readline().rstrip()

def main():
    a, b, c, d = map(int, input().split())
    cd_gcd = c * d // fractions.gcd(c, d)
    count_cd = lambda n: n - math.floor(n / c) - math.floor(n / d) + math.floor(n / cd_gcd)
    print(count_cd(b) - count_cd(a-1))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import fractions
def input(): return sys.stdin.readline().rstrip()

def main():
    a, b, c, d = map(int, input().split())
    def count_ab(n):
        return math.floor(b / n) - math.ceil(a / n) + 1
    c_cnt = count_ab(c)
    d_cnt = count_ab(d)
    cd_cnt = count_ab(c * d // fractions.gcd(c, d))

    print(b - a - c_cnt - d_cnt + cd_cnt + 1)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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


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

# B以下で、CでもDでも割り切れない数の個数を求める, 0は入っていないから範囲はB個
b_not_division = B - (B//C + B//D - B//(C*D/gcd(C, D)))
# A-1以下で、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)

Submission status: Wrong Answer

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


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

# B以下で、CでもDでも割り切れない数の個数を求める, 0は入っていないから範囲はB個
b_not_division = B - (B//C + B//D - B//(C*D//gcd(C, D)))
# A-1以下で、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)

Submission status: Wrong Answer

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


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

# B以下で、CでもDでも割り切れない数の個数を求める, 0は入っていないから範囲はB個
b_not_division = B - (B//C + B//D - B//(C*D//gcd(C, D)))
# A-1以下で、CでもDでも割り切れない数の個数を求める
A += 1
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)

Submission status: Wrong Answer

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


A, B, C, D = map(int, input().split())
if B % A == 0:
    t = 1
else:
    t = 0
# B以下で、CでもDでも割り切れない数の個数を求める
b_not_division = B - (B//C + B//D - B//(C*D//gcd(C, D)))
# A-1以下で、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+t)

Submission status: Wrong Answer

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


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

# B以下で、CでもDでも割り切れない数の個数を求める
b_not_division = B - (B//C + B//D - B//(C*D//gcd(C, D)))
# A-1以下で、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)

Submission status: Wrong Answer

Solution code:
def pgcd(m,n): 
    while m%n: 
        r=m%n 
        m=n 
        n=r 
    return n 
 
def ppcm(m,n): 
    return m*n//pgcd(m,n)


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

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(x,y):
	return int((x*y)/fractions.gcd(x,y))
count = 0
A,B,C,D= map(int,input().split())
lcm = lcm(C,D)
E = int((A-1)/C)
F = int((A-1)/D)
G = int((A-1)/lcm)
H = int(B/C)
I = int(B/D)
J = int(B/lcm)

count = (B-A+1)-((H-E)+(I-F)-(J-G))

print(count)

Submission status: Wrong Answer

Solution code:
import fractions

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

A,B,C,D= map(int,input().split())
lcm = lcm(C,D)
E = int((A-1)/C)
F = int((A-1)/D)
G = int((A-1)/lcm)
H = int(B/C)
I = int(B/D)
J = int(B/lcm)

count = (B-A+1)-((H-E)+(I-F)-(J-G))

print(count)

Submission status: Wrong Answer

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

ac = int((A-1)/C)
ad = int((A-1)/D)
bc = int(B/C)
bd = int(B/D)

c = bc - ac
d = bd - ad

# gcdは最大公約数(greatest common divisor)の意
def gcd(x, y):
    while y != 0:
        x, y = y, x%y
    return x

#最小公倍数
def lcm(a, b):
    return a*b//gcd(a, b)

baisu = lcm(C,D)
a_baisu = int((A-1)/baisu)
b_baisu = int(B/baisu)


print(B-A+1-c-d+(b_baisu-a_baisu))

Submission status: Wrong Answer

Solution code:
import fractions
def smallestCommon(a,b):
    return a*b/fractions.gcd(a,b)

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

    s1 = int(a / c) - 1 if a % c == 0 else a // c
    s2 = b // c
    m1 = s2 - s1

    s3 = int(a / d) - 1 if a % d == 0 else a // d
    s4 = b // d
    m2 = s4 - s3



    common = int(smallestCommon(c,d))

    c1 = a // common
    c2 = b // common
    m3 = c2 - c1

    total = int(b - a + 1)

    return total - (m1 + m2 - m3)


S = input().split(" ")
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

result = caluclate(A,B,C,D)

print(result)

Submission status: Wrong Answer

Solution code:
#ABC_131_C
import fractions
A,B,C,D=list(map(int,input().split()))
#B以下の答え
CD_lcm=int(C*D/fractions.gcd(C,D))

underB=B-int(B/C)-int(B/D)+int(B/CD_lcm)
underA_1=A-1-int((A-1)/C)-int((A-1)/D)+int((A-1)/CD_lcm)

print(underB-underA_1)

Submission status: Wrong Answer

Solution code:
#ABC_131_C
import fractions
A,B,C,D=list(map(int,input().split()))
#B以下の答え

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

underB=B-int(B/C)-int(B/D)+int(B/CD_lcm)
underA_1=A-1-int((A-1)/C)-int((A-1)/D)+int((A-1)/CD_lcm)
print(underB-underA_1)

Submission status: Wrong Answer

Solution code:
#ABC_131_C
import fractions

A,B,C,D=list(map(int,input().split()))
underB=B-int(B/C)-int(B/D)+int(B/(C*D//fractions.gcd(C,D)))
underA_1=A-1-int((A-1)/C)-int((A-1)/D)+int((A-1)/(C*D//fractions.gcd(C,D)))

print(underB-underA_1)

Submission status: Wrong Answer

Solution code:
#ABC_131_C
import fractions

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

def f(A,B,X):
    return int(B/X)-int((A-1)/X)

C_num=f(A,B,C)
D_num=f(A,B,D)

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

CD_num=f(A,B,CD_m)

ans=(B-A+1)-C_num-D_num+CD_num
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC_131_C
import fractions

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


def f(A,B,X):
    if A%X==0 or B%X==0:
        X_num=1+(B-A)//X
    else:
        X_num=(B-A)//X
    return X_num


C_num=f(A,B,C)
D_num=f(A,B,D)

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

CD_num=f(A,B,CD_m)

ans=(B-A+1)-C_num-D_num+CD_num
print(ans)

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
x=(b-a+1)//c
y=(b-a+1)//d
z=(b-a+1)//(c*d)

print(b-a+1-x-y+z)

Submission status: Wrong Answer

Solution code:
def gcd(x, y): 
	while(y): 
   		x, y = y, x % y 
	return x 
a,b,c,d=map(int,input().split())
m=((c*d)//(gcd(c,d)))
di=b-a+1
if a%c==0:
  c1=(b//c-a//c)+1
else:
  c1=(b//c-a//c)
if a%d==0:
  c2=(b//d-a//d)+1
else:
  c2=(b//d-a//d)
if a%m==0 and m!=a or m!=b:
  c3=(b//m-a//m)+1
else:
  c3=(b//m-a//m)
print(di-(c1+c2-c3))

Submission status: Wrong Answer

Solution code:
def gcd(x, y): 
	while(y): 
   		x, y = y, x % y 
	return x 
a,b,c,d=map(int,input().split())
m=((c*d)//(gcd(c,d)))
di=b-a
c1=(b//c-(a-1)//c)
c2=(b//d-(a-1)//d)
c3=(b//m-(a-1)//m)
print(di-(c1+c2-c3-c3))

Submission status: Wrong Answer

Solution code:
def gcd(x, y): 
	while(y): 
   		x, y = y, x % y 
	return x 
a,b,c,d=map(int,input().split())
m=((c*d)//(gcd(c,d)))
di=b-a
if a%c==0:
  c1=(b//c-a//c)+1
else:
  c1=(b//c-a//c)
if a%d==0:
  c2=(b//d-a//d)+1
else:
  c2=(b//d-a//d)
if a%m==0:
  c3=(b//m-a//m)+1
else:
  c3=(b//m-a//m)
print(di-(c1+c2-c3-c3)+1)

Submission status: Wrong Answer

Solution code:
def gcd(x, y): 
	while(y): 
   		x, y = y, x % y 
	return x 
a,b,c,d=map(int,input().split())
m=((c*d)//(gcd(c,d)))
di=b-a
if a%c==0:
  c1=(b//c-a//c)+1
else:
  c1=(b//c-a//c)
if a%d==0:
  c2=(b//d-a//d)+1
else:
  c2=(b//d-a//d)
if a%m==0 and m!=a or m!=b:
  c3=(b//m-a//m)+1
else:
  c3=(b//m-a//m)
print(di-(c1+c2-c3-c3))

Submission status: Wrong Answer

Solution code:
def gcd(x, y): 
	while(y): 
   		x, y = y, x % y 
	return x 
a,b,c,d=map(int,input().split())
m=((c*d)//(gcd(c,d)))
di=b-a
if a%c==0:
  c1=(b//c-a//c)+1
else:
  c1=(b//c-a//c)
if a%d==0:
  c2=(b//d-a//d)+1
else:
  c2=(b//d-a//d)
if a%m==0:
  c3=(b//m-a//m)+1
else:
  c3=(b//m-a//m)
print(di-(c1+c2-c3-c3))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())

x1=b//c-a//c
x2=b//d-a//d
sks=c * d // fractions.gcd(c,d)
x3=b//sks-a//sks
ans=b-a-(x1+x2-x3)
print (ans)

Submission status: Wrong Answer

Solution code:
import fractions
def smallestCommon(a,b):
    return a*b/fractions.gcd(a,b)

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

    s1 = 2 if a / c < 2 else int(a / c)
    s2 = 2 if b / c < 2 else int(b / c)
    s3 = 2 if a / d < 2 else int(a / d)
    s4 = 2 if b / d < 2 else int(b / d)

    m1 = s2 - s1 + 1
    m2 = s4 - s3 + 1
    m3 = 0
    common = smallestCommon(c,d)
    commonB = common / c

    m3 = (s2 //commonB) - (s1 // commonB)

    return int(b - a + 1 - (m1 + m2 - m3))


S = input().split(" ")
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

result = caluclate(A,B,C,D)

print(result)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

    s1 = 2 if a / c < 2 else int(a / c)
    s2 = 2 if b / c < 2 else int(b / c)
    s3 = 2 if a / d < 2 else int(a / d)
    s4 = 2 if b / d < 2 else int(b / d)

    m1 = s2 - s1 + 1
    m2 = s4 - s3 + 1
    m3 = 0
    common = smallestCommon(c,d)
    commonB = common / c

    m3 = (s2 //commonB) - (s1 // commonB)

    return int(b - a + 1 - (m1 + m2 - m3))


S = input().split(" ")
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

result = caluclate(A,B,C,D)

print(result)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
import fractions
ans = b - b//c - a-(a-1)//c + b- b//d -b - (a-1)//d + (c*d // fractions.gcd(c, d))
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
import fractions
ans = (b-a) - ((b-a+1)//c) - ((b-a+1)//d) + (b-a+1)// (c*d // fractions.gcd(c, d))
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
import fractions
ans = (b-a+1) - ((b-a+1)//c) - ((b-a+1)//d) + (b-a+1)// (c*d // fractions.gcd(c, d))
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
import fractions
ans = (b-a+1) - ((b-a+1)//c) - ((b-a+1)//d) + (b-a+1)// (c*d / fractions.gcd(c, d))
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = (b-a) - ((b-a)//c) - ((b-a)//d) + ((b-a)//(c*d))
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
import math
ans = (b-a) - math.ceil((b-a)/c) - math.ceil((b-a)/d) + math.ceil((b-c)/(c*d))
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
ans = 0

for i in (a,b+1):
    if i%c != 0 and i%d != 0:
        ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())
if a == b:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)
    exit()
cd_lcm = c * d // gcd(c, d)
print(b - a + 1 - (b // c - a // c) - (b // d - a // d) + (b // cd_lcm - a // cd_lcm))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())
cd_lcm = c * d // gcd(c, d)
l = b - a
print(l - (l // c + l // d - l // cd_lcm))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
def ans():
    e = b-a+1
    f = (b//c) + (b//d) - (b//fractions.gcd(c,d))
    g = ((a-1)//c) + ((a-1)//d) -((a-1)//fractions.gcd(c,d))

    return(e-(f-g))
ans = ans()
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
def ans():
    e = b-a+1
    f = b//c + b//d - b//fractions.gcd(c,d)
    g = (a-1)//c + (a-1)//d -(a-1)//fractions.gcd(c,d)

    return(e-(f-g))
ans = ans()
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
def ans():
    return((b-a+1) - ((b//c + b//d - b//(fractions.gcd(c,d))) - ((a-1)//c + (a-1)//d - (a-1)//(fractions.gcd(c,d)))))
ans = ans()
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
def ans():
    return((b-a+1) - ((b//c + b//d - b//(c*d)) - ((a-1)//c + (a-1)//d - (a-1)//(c*d))))
ans = ans()
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
count = 0
for i in range(a,b):
    if i%c!=0:
        if i%d!=0:
            count += 1

print(count)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
import fractions
cd_lcm=c*d/fractions.gcd(c,d)
b_count=b-(b//c+b//d-b//cd_lcm)
a_count=a-1-((a-1)//c+(a-1)//d-(a-1)//cd_lcm)
print(int(b_count-a_count))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
import fractions
cd_gcd=c*d/fractions.gcd(c,d)
l=b-a+1
print(int(l-(l//c+l//d-l//(cd_gcd))))#c*d←ここをc.dの最小公倍数にする

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
import fractions
cd_gcd=c*d/fractions.gcd(c,d)
l=b-a+1
print(l-(l//c+l//d-l//(cd_gcd)))#c*d←ここをc.dの最小公倍数にする

Submission status: Wrong Answer

Solution code:
import math

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

    quotient = []
    quotient = []
    for i, x in enumerate([c, d, c*d]):
        temp1 = (b / x) - (a / x)
        temp2 = math.ceil(temp1)
        quotient.append(temp2)
    temp1 = b - a + 1
    ans = temp1 - (quotient[0] + quotient[1]) + quotient[2]
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
l=b-a+1
if (a%c==0 or b%c==0) and (a%d==0 or b%d==0):
    print(l-(l//c+l//d-l//(c*d)))
else:
    print(l-(l//c+l//d-l//(c*d))-1)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
l=b-a+1
print(l-(l//c+l//d-l//(c*d)))

Submission status: Wrong Answer

Solution code:
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 = list(map(int, input().split()))
 
lcmCD = lcm(C, D)
 
divB = (B // C) + (B // D) - (B // lcmCD)
divA_1 = ((A - 1) // C) + ((A - 1) // D) - ((A - 1) // lcmCD)
print((B - A) - (divB - divA_1) + 1)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = [int(s) for s in input().split()]
g=fractions.gcd(C,D)
print(B-(A-1)
      -(B//C)+((A-1)//C)
      -(B//D)+((A-1)//D)
      +(B//g)-((A-1)//g))

Submission status: Wrong Answer

Solution code:
A,B,C,D = [int(s) for s in input().split()]
print(B-(A-1)
      -(B//C)+((A-1)//C)
      -(B//D)+((A-1)//D)
      +(B//(C*D))-((A-1)//(C*D)))

Submission status: Wrong Answer

Solution code:
import math


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


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


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

# 最小公倍数
cd = lcm(c, d)

cdiv = int(b / c) - int((a - 1) / c)
ddiv = int(b / d) - int((a - 1) / d)
cddiv = int(b / cd) - int((a - 1) / cd)
ans = b - a + 1 - cdiv - ddiv + cddiv

print(ans)

Submission status: Wrong Answer

Solution code:
import math


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


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


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

# 最小公倍数
cd = lcm(c, d)

cdiv = int(b / c) - int((a - 1) / c)
ddiv = int(b / d) - int((a - 1) / d)
cddiv = int(b / (cd)) - int((a - 1) / (cd))
ans = (b - a + 1) - (cdiv + ddiv-cddiv)

print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
ans = 0

if (d % c == 0):
    cdiv = int(b / c) - int((a - 1) / c)
    ans = (b - a + 1) - cdiv
else:
    cdiv = int(b / c) - int((a - 1) / c)
    ddiv = int(b / d) - int((a - 1) / d)
    cddiv = int(b / (c * d)) - int((a - 1) / (c * d))
    ans = (b - a + 1) - (cdiv + ddiv-cddiv)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
	a,b,c,d = map(int,input().split())

	#about c
	ans_c_a = (a-1)//c
	ans_c_b = b//c
	# print(ans_c_b)
	ans_c = ans_c_b - ans_c_a
	print("ans_c = {}".format(ans_c))

	#about d
	ans_d_a = (a-1)//d
	ans_d_b = b//d
	ans_d = ans_d_b - ans_d_a
	print("ans_d = {}".format(ans_d))

	#aboud c*d
	import fractions
	saisyou = (c * d) // fractions.gcd(c,d)
	print(saisyou)
	ans_saisyou_a = (a-1)//saisyou
	ans_saisyou_b = b//saisyou
	ans_saisyou = ans_saisyou_b - ans_saisyou_a
	print("ans_saisyou = {}".format(ans_saisyou))

	print(int( b-a+1 - (ans_c + ans_d - ans_saisyou) ))


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	a,b,c,d = map(int,input().split())

	#about c
	ans_c_a = a//c
	ans_c_b = (b+1)//c
	# print(ans_c_b)
	ans_c = ans_c_b - ans_c_a
	# print("ans_c = {}".format(ans_c))

	#about d
	ans_d_a = a//d
	ans_d_b = (b+1)//d
	ans_d = ans_d_b - ans_d_a
	# print("ans_d = {}".format(ans_d))

	#aboud c*d
	import fractions
	saisyou = c*d / fractions.gcd(c,d)
	# print(saisyou)
	ans_saisyou_a = a//saisyou
	ans_saisyou_b = (b+1)//saisyou
	ans_saisyou = ans_saisyou_b - ans_saisyou_a
	# print("ans_saisyou = {}".format(ans_saisyou))

	print(int(len(range(a,b+1)) - (ans_c + ans_d - ans_saisyou)))


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
def gcd(x,y):
    while y!=0:
        x,y=y,x%y
    return x
l=(c*d)//gcd(c,d)
print(b-a+1-((b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//l)-((a-1)//l)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())
print(b-a-b//c-b//d+b//(c*d//gcd(c,d))-(-(a-1)//c-(a-1)//d+(a-1)//(c*d//gcd(c,d))))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d=map(int,input().split())
print(b-a-(b-a)//c-(b-a)//d+(b-a)//(c*d//gcd(c,d)))

Submission status: Wrong Answer

Solution code:
def main():
	# import math
	import fractions
	a,b,c,d = map(int,input().split())
	ans = 0
	
	e = int((c*d) / fractions.gcd(c,d))

	i = int(b/c)
	t = int(b/d)
	l = int(b/e)

	while a <= i * c <= b:
		ans += 1
		i -= 1

	while a <= t * d <= b:
		ans += 1
		t -= 1
	
	while a <= l * e <= b:
		ans -= 1
		l -= 1

	print(int(len(range(a,b+1)))-ans)

if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
cnum = B//C-(A-1)//C
dnum = B//D-(A-1)//D
mx = max(C, D)
mn = min(C, D) 
while mn != 0:
    mx, mn = mn, mx%mn
    #print(mx)
    E = C*D/mx
enum = B//E-(A-1)//E
ansback = cnum+dnum-enum
ans = B-A+1-ansback
print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

A, B, C, D = MAP()
# Cで割り切れない数 = BとAの間の数 - Cで割り切れる数
c = (B-A)-((B-A)//C)
d = (B-A)-((B-A)//D)
e = (B-A)-((B-A)//(C*D))

#print(c,d,e)

print(c+d-e)

Submission status: Wrong Answer

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

def f(x):
  l=x//C
  m=x//D
  k=C*D/gcd(C,D)
  n=x//k
  
  return(x-l-m+n)

print(f(B)-f(A-1))

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int,input().split())
g = fractions.gcd(C,D)
l = C*D//g
print(B-A+1-(B-1)//C-(B-1)//D+(B-1)//l+(A-1)//C+(A-1)//D-(A-1)//l)

Submission status: Wrong Answer

Solution code:
import fractions

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

lcm = c*d // fractions.gcd(c,b)


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)

Submission status: Wrong Answer

Solution code:
import fractions

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

lcm = c*d // fractions.gcd(c,b)


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

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
cnt_c=b//c-(a-1)//c
cnt_d=b//d-(a-1)//d
cnt_cd=b//(c*d)-(a-1)//(c*d)
print(b-a+1-cnt_c-cnt_d+cnt_cd)

Submission status: Wrong Answer

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

x = a//c
if a%c != 0:
  x += 1
y = a//d
if a%d != 0:
  y += 1
xy = a//(c*d)
if a%(c*d) != 0:
  xy += 1

t1 = max(0, b//c - x+1)
t2 = max(0, b//d - y+1)
t3 = max(0, b//(c*d) - xy+1)

print(str((b-a+1) - (t1+t2-t3)))

Submission status: Wrong Answer

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

x = b//c + b//d - b//(c*d)
y = (a-1)//c + (a-1)//d - (a-1)//(c*d)

print((b-a+1)-(x-y))

Submission status: Wrong Answer

Solution code:
abcd = list(map(int,input().split()))
MIN = abcd[0]
MAX = abcd[1]
C = abcd[2]
D = abcd[3]
ans = []
solv = []
for i in range(MIN,MAX):
        if i % C == 0 or i % D == 0:
            ans.append(i)
for i in range(MIN,MAX):
    if i not in ans:
        solv.append(i)
print(len(solv))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
print(int(b-a+1-(b//c-(a-1)//c+b//d-(a-1)//d-b//(c*d/fractions.gcd(c,d))+(a-1)//(c*d/fractions.gcd(c,d)))))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
print(b-a+1-(b//c-(a-1)//c+b//d-(a-1)//d-b//(c*d/fractions.gcd(c,d))+(a-1)//(c*d/fractions.gcd(c,d))))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())
CC=int(B/C)-int((A-1)/C)
DD=int(B/D)-int((A-1)/D)
import fractions
F=(C*D)//fractions.gcd(C,D)
FF=int(B/F)-int((A-1)/F)
print(B-A+1-CC-DD+FF)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
if a%c==0 and a%d==0:
  print(b-a-(int(b/c)-int(a/c)+int(b/d)-int(a/d)))
elif a%c==0 and a%d!=0:
  print(b-a-(int(b/c)-int(a/c)+int(b/d)-(int(a/d)+1)))
elif a%c!=0 and a%d==0:
  print(b-a-((int(b/c)-(int(a/c)+1))+(int(b/d)-(int(a/d)))))
else:
  print(b-a-((int(b/c)-(int(a/c)+1))+(int(b/d)-(int(a/d)+1))))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
if a%c==0 and a%d==0:
  print(b-a-(int(b/c)-int(a/c)+int(b/d)-int(a/d)))
elif a%c==0 and a%d!=0:
  print(b-a-(int(b/c)-int(a/c)+int(b/d)-(int(a/d)+1)))
elif a%c!=0 and a%d==0:
  print(b-a-((int(b/c)-(int(a/c)+1))+(int(b/d)-(int(a/d)))))
else:
  print(b-a+1-((int(b/c)-(int(a/c)+1))+(int(b/d)-(int(a/d)+1))))

Submission status: Wrong Answer

Solution code:
import fractions as ff
a,b,c,d=map(int,input().split())
if a%c==0:
    if b%d==0:
        cnt=1
    else:
        cnt=0
elif a%d==0:
    if b%c==0:
        cnt=1
    else:
        cnt=0
else:
    cnt=0
if cnt==1:
    print((b-b//c-b//d+b//(c*d//ff.gcd(c,d)))-(a-a//c-a//d+a//(c*d//ff.gcd(c,d))))
else:
    print((b-b//c-b//d+b//(c*d//ff.gcd(c,d)))-(a-a//c-a//d+a//(c*d//ff.gcd(c,d)))+1)

Submission status: Wrong Answer

Solution code:
import fractions as ff
a,b,c,d=map(int,input().split())
if c<d:
    if a%c==0 and b%d==0:
        cnt=1
    else:
        cnt=0
else:
    if a%d==0 and b%c==0:
        cnt=1
    else:
        cnt=0
if cnt==1:
    print((b-b//c-b//d+b//(c*d//ff.gcd(c,d)))-(a-a//c-a//d+a//(c*d//ff.gcd(c,d))))
else:
    print((b-b//c-b//d+b//(c*d//ff.gcd(c,d)))-(a-a//c-a//d+a//(c*d//ff.gcd(c,d)))+1)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
b=b+1

ac=a//c
ad=a//d
bc=b//c
bd=b//d

f=fractions.gcd(c,d)
f=c*d//f

acd=a//f
bcd=b//f

print((b-a)-(bc-ac)-(bd-ad)+(bcd-acd))

Submission status: Wrong Answer

Solution code:
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)//(c*d)+1  
print(b-a+1-c2-d2+cd2)

Submission status: Wrong Answer

Solution code:
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)//(c*d)+1  
print(b-a+1-max(0,c2)-max(0,d2)+max(0,cd2))

Submission status: Wrong Answer

Solution code:
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)//(c*d)+1  
print(b-a+1-c2-d2+max(0,cd2))

Submission status: Wrong Answer

Solution code:
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+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)//(c*d)+1  
print(b-a+1-max(0,c2)-max(0,d2)+max(0,cd2))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
import fractions as f
cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
gcd=f.gcd(c,d)
lcm=c*d//gcd
cd=b//lcm-a//lcm
print((b-a+1)-(cc+dd-cd))

Submission status: Wrong Answer

Solution code:
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-1)//d+1
  print(b-a-(b-d1*d)//d)
  exit()
elif d>b:
  c1=(a-1)//c+1
  print(b-a-(b-c1*c)//c)
  exit()
else :
  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)//(c*d)+1
  print(b-a+1-c2-d2+max(0,cd2))

Submission status: Wrong Answer

Solution code:
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))

Submission status: Wrong Answer

Solution code:
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-1)//d+1
  print(b-a-(b-d1*d)//d)
  exit()
elif d>b:
  c1=(a-1)//c+1
  print(b-a-(b-c1*c)//c)
  exit()
else :
  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)//(c*d)+1
  print(b-a+1-c2-d2+cd2)

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

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