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 math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//(c*d/math.gcd(c,d)) - (a-1)//(c*d/math.gcd(c,d))
s12=int(s12)
#print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

Solution code:
import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//(c*d/math.gcd(c,d)) - (a-1)//(c*d/math.gcd(c,d))
s12=int(s12)
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

Solution code:
import math

a,b,c,d = map(int,input().split())
lcm=c*d/math.gcd(c,d)

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=b//lcm - (a-1)//lcm

print(int(b-a+1-(s1+s2-s12)))

Submission status: Wrong Answer

Solution code:
import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=int( b//(c*d/math.gcd(c,d)) - (a-1)//(c*d/math.gcd(c,d)) )
print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

Solution code:
import math

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

s1=b//c - (a-1)//c
s2=b//d - (a-1)//d
s12=int( b//(c*d/math.gcd(c,d)) - (a-1)//(c*d/math.gcd(c,d)) )
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

Solution code:
import math

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

s1=b//c - a//c
s2=b//d - a//d
s12=int( b//(c*d/math.gcd(c,d)) - a//(c*d/math.gcd(c,d)) )

print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

Solution code:
import math

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

s1=b//c - a//c
s2=b//d - a//d
s12=int( b//(c*d/math.gcd(c,d)) - a//(c*d/math.gcd(c,d)) )
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

Solution code:
import math

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

s1=b//c - math.ceil(a/c) + 1
s2=b//d - math.ceil(a/d) + 1
s12=int( b//(c*d/math.gcd(c,d)) - math.ceil(a/(c*d/math.gcd(c,d))) + 1 )
print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

Solution code:
import math

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

s1=b//c - math.ceil(a/c) + 1
s2=b//d - math.ceil(a/d) + 1
s12=int( b//(c*d/math.gcd(c,d)) - math.ceil(a/(c*d/math.gcd(c,d))) + 1 )
print(s1,s2,s12)
print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

Solution code:
import math

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

s1=b//c - math.ceil(a/c) + 1
s2=b//d - math.ceil(a/d) + 1
s12=b//(c*d) - math.ceil(a/(c*d)) + 1

print(b-a+1-(s1+s2-s12))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(B-B//C-B//D+B//(C*D//math.gcd(C,D))-(A-A//C-A//D+A//(C*D//math.gcd(C,D)))+1)

Submission status: Wrong Answer

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, C, D = LI()

    # Xより小さい自然数でCでもDでも割り切れないものの個数
    def f(X):
        ret = X - X // C - X // D + X // (C * D // math.gcd(C, D))
        return ret

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

if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
 
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
 
a,b,c,d=map(int,input().split())
c_div=(b//c)-math.ceil(a/c)+1
d_div=(b//d)-math.ceil(a/d)+1
cd_div=(b//lcm(c,d))-math.ceil(a/lcm(c,d))+1
 
ans=(b-a+1)-((c_div)+(d_div)-(cd_div))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

c_div=math.floor(b/c)-math.floor((a-1)/c)
d_div=math.floor(b/d)-math.floor((a-1)/d)
cd_div=math.floor(b/lcm(c,d))-math.floor((a-1)/lcm(c,d))

ans=(b-a+1)-((c_div)+(d_div)-(cd_div))
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

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

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

c_div=math.floor(b/c)-math.floor((a-1)/c)
d_div=math.floor(b/d)-math.floor((a-1)/d)
cd_div=math.floor(b/lcm(c,d))-math.floor((a-1)/lcm(c,d))

ans=(b-a+1)-((c_div)+(d_div)-(cd_div))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

a,b,c,d=map(int,input().split())
c_div=math.floor(b/c)-math.ceil(a/c)+1
d_div=math.floor(b/d)-math.ceil(a/d)+1
cd_div=math.floor(b/lcm(c,d))-math.ceil(a/lcm(c,d))+1

ans=(b-a+1)-((c_div)+(d_div)-(cd_div))
print(ans)

Submission status: Wrong Answer

Solution code:
def abc131c_anti_division():
    import math
    cnt = 0
    a, b, c, d = map(int, input().split())
    cnt = b//c - math.ceil(a/c) + 1
    cnt += b//d - math.ceil(a/d) + 1
    e = (c*d)//math.gcd(c, d)
    cnt -= (b // e - math.ceil(a / e) + 1)
    print(int(b-a+1-cnt))
abc131c_anti_division()

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
dcou=b//d-(a-1)//d
ccou=b//c-(a-1)//c
from math import gcd
dc=d*c/gcd(d,c)
dccou=b//dc-(a-1)//dc
ans=b-a-dcou-ccou+dccou+1
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
A, B, C, D = map(int, input().split())
 
# CでもDでも割り切れない = 全体(a) - Cで割り切れる(b) + Dで割り切れる(c) + CでもDでも割り切れる(d)
lcm = C*D // math.gcd(C, D)
a = B-A+1

if A % C != 0 and B % C != 0: b = a // C
else: b = a // C + 1
if A % D != 0 and B % D != 0: c = a // D
else: c = a // D + 1
if A % lcm != 0 and B % lcm != 0: d = a // lcm
else: d = a // lcm + 1

print(a-b-c+d)

Submission status: Wrong Answer

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

#A-1以下のC,Dの倍数の個数
under_ac = int((A-1)/C)
under_ad = int((A-1)/D)

#B以下のC,Dの倍数の個数
under_bc = int(B/C)
under_bd = int(B/D)

#重複部分
CD = C*D

#CとDの最大公約数を求める
def gcd(a,b):
    if a<b:
        a,b = b,a
    while True:
        r = a%b
        if r ==0:
            return b
        else:
            a = b
            b = r

g = gcd(C, D)
l = int(CD/g) #C,Dの最小公倍数

#重複して引いた数
al = int((A-1)/l)
bl = int(B/l)

under_a = (A-1) - (under_ac+under_ad) + al
under_b = B - (under_bc+under_bd) + bl

print(under_b - under_a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
q=[a,b+1]
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]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
q=[a-1,b]
for w in range(0,2):
    x=int(q[w]/c)
    y=int(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=int(q[w]/l)
    q[w]=q[w]-x-y+z
print(q[1]-q[0])

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
q=[a,b+1]
for w in range(0,2):
    x=int(q[w]/c)
    y=int(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=int(q[w]/l)
    q[w]=q[w]-x-y+z
print(q[1]-q[0])

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 131
# C - Anti-Division
import math

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

A,B,C,D=map(int,input().split())
bc=B//C
ac=A//C
cnum=bc-ac

bd=B//D
ad=A//D
dnum=bd-ad


lcmcd=lcm(C,D)
blcmcd=B//lcmcd
alcmcd=A//lcmcd
lcmcdnum=blcmcd-alcmcd


if lcm(C,D)==C*D:
    print(B-A-cnum-dnum+lcmcdnum)
else:
    print(B-A-cnum-dnum+lcmcdnum +1)

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 131
# C - Anti-Division
import math

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

A,B,C,D=map(int,input().split())
bc=B//C
ac=A//C
cnum=bc-ac

bd=B//D
ad=A//D
dnum=bd-ad


lcmcd=lcm(C,D)
blcmcd=B//lcmcd
alcmcd=A//lcmcd
lcmcdnum=blcmcd-alcmcd

print(B-A-cnum-dnum+lcmcdnum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int, input().split())
e = c*d/(math.gcd(c,d))

ac = math.floor((a-1)/c)
bc = math.floor(b/c)
acd = math.floor((a-1)/e)
ad = math.floor((a-1)/d)
bd = math.floor(b/d)
bcd = math.floor(b/e)

xa = ac + ad - acd

xb = bc + bd - bcd

print(int(b-a+1-(xb-xa)))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int, input().split())
e = c*d/(math.gcd(c,d))

ac = math.floor(a/c)
bc = math.floor(b/c)
acd = math.floor(a/e)
ad = math.floor(a/d)
bd = math.floor(b/d)
bcd = math.floor(b/e)

xa = ac + ad - acd

xb = bc + bd - bcd

print(int(b-a+1-(xb-xa)))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int, input().split())
e = c*d/(math.gcd(c,d))

ac = math.ceil(a/c)
bc = math.floor(b/c)


ad = math.ceil(a/d)
bd = math.floor(b/d)

ae = math.ceil(a/e)
be = math.floor(b/e)

if b/c-a/c<1:
  xc = 0
else:
  xc = bc-ac + 1
if b/d-a/d<1:
  xd = 0
else:
  xd = bd-ad + 1
if b/e-a/e<1:
  xe = 0
else:
  xe = be-ae + 1
  
f = xc + xd - xe
g = b-a+1
h = g - f
print(h)

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 and i % d != 0:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import math

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

n=b-a+1

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

cc=math.ceil(n/c)
dc=math.ceil(n/d)
xc=math.ceil(n/x)

print(n-cc-dc+xc)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
A-=1
x=B//C-A//C
y=B//D-A//D
z=B//(C*D)-A//(C*D)
print(B-A-x-y+z)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
a=(B//C)-(A//C)
b=(B//D)-(A//D)
c=(B//(C*D))-(A//(C*D))
print(B-A-a-b+c)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
a=(B//C)-(A//C)
b=(B//D)-(A//D)
c=(B//(C+D))-(A//(C+D))
print(B-A-a-b+c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int,input().split())
e=a*b//math.gcd(a,b)
if a%c==0:
  p=b//c-a//c+1
else:
  p=b//c-a//c
if a%d==0:
  q=b//d-a//d+1
else:
  q=b//d-a//d
if a%e==0:
  r=b//e-a//e+1
else:
  r=b//e-a//e
print(b-a+1-(p+q-r))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
h = a-b + 1
e = c*d
m = h//c + int(a%c==0)
k = h//d + int(a%d==0) 
l = h//e + int(a%e==0)
print(h-(m+k-l))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    A,B,C,D = map(int,input().split())
    #Cで割り切れる数の探索
    tmpC = (A-1)//C
    tmpC2 = (B)//C
    numC = tmpC2 - tmpC
    #Dで割り切れる数の探索
    tmpD = (A-1)//D
    tmpD2 = (B)//D
    numD = tmpD2 - tmpD
    #CでもDで割り切れるもの
    if C == D:
        ans = B-A+1-numC
    elif C > D:
        if C%D != 0:
            tmpCD = (A-1)//(C*D)
            tmpCD2 = (B)//(C*D)
            numCD = tmpCD2 - tmpCD
            ans = B-A+1-numC-numD+numCD
        else:
            ans = B-A+1-numD
    else:
        if D%C != 0:
            tmpCD = (A-1)//(C*D)
            tmpCD2 = (B)//(C*D)
            numCD = tmpCD2 - tmpCD
            ans = B-A+1-numC-numD+numCD
        else:
            ans = B-A+1-numC
    return ans

print(main())

Submission status: Wrong Answer

Solution code:
from math import gcd
A, B, C, D = map(int, input().split())
E = C*D
ans = B-A+1 - (B//C-(A-1)//C + B//D-(A-1)//D - B//E-(A-1)//E)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import gcd
A, B, C, D = map(int, input().split())
E = C*D//gcd(C, D)
ans = B-A+1 - (B//C-(A-1)//C + B//D-(A-1)//D - B//E-(A-1)//E)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
ApC = A % C
#if ApC == 0:
#    ApC= C
sAC = A+(C-ApC)
if sAC > B:
    if A% C == 0:
        cc = 1
    else:
        cc = 0
else:
    cc = (B-sAC+1)//C+1

ApD = A % D
#if ApD == 0:
#    ApD= D
sAD = A+(D-ApD)
if sAD > B:
    if A% D == 0:
        dc = 1
    else:
        dc = 0
else:
    dc = (B-sAD+1)//D+1

cd = math.floor(C * D / math.gcd(C, D))

ApCD = A % (cd)
#if ApCD == 0:
#    ApCD= cd

sACD = A+(cd-ApCD)
if sACD > B:
    if A% cd == 0:
        cdc = 1
    else:
        cdc = 0
else:
    cdc = (B-sACD+1)//(cd)+1

#print(cc,dc,cdc)
print(B-A+1-cc-dc+cdc)

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
ApC = A % C
#if ApC == 0:
#    ApC= C
sAC = A+(C-ApC)
if sAC > B:
    cc = 0
else:
    cc = (B-sAC+1)//C+1

ApD = A % D
#if ApD == 0:
#    ApD= D
sAD = A+(D-ApD)
if sAD > B:
    dc = 0
else:
    dc = (B-sAD+1)//D+1

cd = math.floor(C * D / math.gcd(C, D))

ApCD = A % (cd)
#if ApCD == 0:
#    ApCD= cd

sACD = A+(cd-ApCD)
if sACD > B:
    cdc = 0
else:
    cdc = (B-sACD+1)//(cd)+1

#print(cc,dc,cdc)
print(B-A+1-cc-dc+cdc)

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
ApC = A % C
if ApC == 0:
    ApC= C
sAC = A+(C-ApC)
cc = (B-sAC+1)//C+1

ApD = A % D
if ApD == 0:
    ApD= D
sAD = A+(D-ApD)

dc = (B-sAD+1)//D+1

cd = math.floor(C * D / math.gcd(C, D))

ApCD = A % (cd)
if ApCD == 0:
    ApCD= cd

sACD = A+(cd-ApCD)
cdc = (B-sACD+1)//(cd)+1

#print(cc,dc,cdc)
print(B-A+1-cc-dc+cdc)

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
ApC = A % C
sAC = A+(C-ApC)
cc = (B-sAC+1)//C+1

ApD = A % D
sAD = A+(D-ApD)

dc = (B-sAD+1)//D+1

cd = math.floor(C * D / math.gcd(C, D))

ApCD = A % (cd)
sACD = A+(cd-ApCD)
cdc = (B-sACD+1)//(cd)+1

print(B-A+1-cc-dc+cdc)

Submission status: Wrong Answer

Solution code:
import math
A, B, C, D = map(int, input().split())
cnt = 0
LCD = C*D/math.gcd(C,D)

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

print(int(ans))

Submission status: Wrong Answer

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

nc=int((B+0.01)/C)-int((A-0.5)/C)
nd=int((B+0.01)/D)-int((A-0.5)/D)
gg=C*D/math.gcd(C,D)
ncd=int((B+0.01)/gg)-int((A-0.5)/gg)

print(B-A+1-nc-nd+ncd)

Submission status: Wrong Answer

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

nc=int(B/C)-int((A-1)/C)
nd=int(B/D)-int((A-1)/D)
gg=C*D/math.gcd(C,D)
ncd=int(B/gg)-int((A-1)/gg)

print(B-A+1-nc-nd+ncd)

Submission status: Wrong Answer

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

nc=int(B/C)-int((A-1)/C)
nd=int(B/D)-int((A-1)/D)
ncd=int(B/(C*D))-int((A-1)/(C*D))

print(B-A+1-nc-nd+ncd)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C_fix
# CreatedDate:  2020-09-03 20:30:23 +0900
# LastModified: 2020-09-03 20:48:14 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


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


def main():
    a, b, c, d = map(int, input().split())
    if (a/c).is_integer():
        c_cnt = (b-a)//c + 1
    else:
        c_cnt = (b-a)//c
    if (a/d).is_integer():
        d_cnt = (b-a)//d + 1
    else:
        d_cnt = (b-a)//d

    lcm = c * d // gcd(max(c, d), min(c, d))
    if (a/lcm).is_integer():
        lcm_cnt = (b-a)//lcm + 1
    else:
        lcm_cnt = (b-a)//lcm
    print(b-a-c_cnt-d_cnt+lcm_cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#35 C - Anti-Division　
import math
A,B,C,D = map(int,input().split())

# C と D の最小公倍数の個数
lcm = C*D//math.gcd(C,D)
cnt_lcm = B//lcm - A//lcm

# C の倍数の個数
cnt_C = B//C - (A-1)//C 

# D の倍数の個数
cnt_D = B//D - (A-1)//D

# (範囲内の整数) - (C の倍数 + D の倍数 - C,D の公倍数)
ans = (B - A + 1) - (cnt_C + cnt_D - cnt_lcm)

# 範囲が 1 しかないとき
if A == B:
    # C でも D でも割り切れるとき
    if A%C == 0 and A%D == 0:
        print(0)
    else:
        print(1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
#35 C - Anti-Division　
import math
A,B,C,D = map(int,input().split())

# C と D の最小公倍数の個数
lcm = C*D//math.gcd(C,D)
cnt_lcm = B//lcm - A//lcm

# C の倍数の個数
cnt_C = B//C - (A-1)//C 

# D の倍数の個数
cnt_D = B//D - (A-1)//D

# (範囲内の整数) - (C の倍数 + D の倍数 - C,D の公倍数)
ans = (B - A + 1) - (cnt_C + cnt_D - cnt_lcm)

if A == B == C == D:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

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

# C と D の最小公倍数の個数
lcm = C*D//math.gcd(C,D)
cnt_lcm = B//lcm - A//lcm

# C の倍数の個数
cnt_C = B//C - (A-1)//C 

# D の倍数の個数
cnt_D = B//D - (A-1)//D

# (範囲内の整数) - (C の倍数 + D の倍数 - C,D の公倍数)
ans = (B - A + 1) - (cnt_C + cnt_D - cnt_lcm)

if A == B == C == D:
    print(1)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
#35 C - Anti-Division
import math
A,B,C,D = map(int,input().split())

# C と D の最小公倍数の個数
lcm = C*D//math.gcd(C,D)
cnt_lcm = B//lcm - A//lcm

# C の倍数の個数
cnt_C = B//C - (A-1)//C 

# D の倍数の個数
cnt_D = B//D - (A-1)//D

# (範囲内の整数) - (C の倍数 + D の倍数 - C,D の公倍数)
ans = (B - A + 1) - (cnt_C + cnt_D - cnt_lcm)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = map(int, input().split())
ac = (a - 1) // c
bc = b // c
ad = (a - 1) // d
bd = b // d
lcm = c * d // math.gcd(c,d )
acd = (a - 1) // lcm
bcd = (b - 1) // lcm
print((b-a+1)-((bc-ac)+(bd-ad)-(bcd-acd)) )

Submission status: Wrong Answer

Solution code:
import math
#最小公倍数,gcd #cf https://note.nkmk.me/python-gcd-lcm/
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

A,B,C,D = map(int, input().split())
all_numbers = B - A + 1
devidable_C = B//C - math.ceil(A/C) + 1
devidable_D = B//D - math.ceil(A/D) + 1
devidable_CD = B//lcm(C,D) - math.ceil(A/lcm(C,D)) + 1

print(all_numbers - devidable_C - devidable_D + devidable_CD)

Submission status: Wrong Answer

Solution code:
import math

A, B, C, D = map(int, input().split())
CD = int(C * D // math.gcd(C, D))

B_in_C = int(B/C)
B_in_D = int(B/D)
B_in_CD = int(B/(CD))
B_con = B - (B_in_C + B_in_D - B_in_CD)

A = A-1 if A > 1 else A
A_in_C = int(A/C)
A_in_D = int(A/D)
A_in_CD = int(A/(CD))
A_con = A - (A_in_C + A_in_D - A_in_CD)

print(B_con - A_con)

Submission status: Wrong Answer

Solution code:
import math

A, B, C, D = map(int, input().split())
CD = int(C * D / math.gcd(C, D))

B_in_C = int(B/C)
B_in_D = int(B/D)
B_in_CD = int(B/(CD))
B_con = B - (B_in_C + B_in_D - B_in_CD)

A = A-1 if A > 1 else A
A_in_C = int(A/C)
A_in_D = int(A/D)
A_in_CD = int(A/(CD))
A_con = A - (A_in_C + A_in_D - A_in_CD)

print(B_con - A_con)

Submission status: Wrong Answer

Solution code:
import math

A, B, C, D = map(int, input().split())
CD = int(C * D / math.gcd(C, D))

B_in_C = int(B/C)
B_in_D = int(B/D)
B_in_CD = int(B/(CD))
B_con = B - (B_in_C + B_in_D - B_in_CD)

A = A-1
A_in_C = int(A/C)
A_in_D = int(A/D)
A_in_CD = int(A/(CD))
A_con = A - (A_in_C + A_in_D - A_in_CD)

print(B_con - A_con)

Submission status: Wrong Answer

Solution code:
'''
Created on 2020/08/28

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  A,B,C,D=map(int,pin().split())
  M=B//C+B//D-B//(C*D)
  m=(A-1)//C+(A-1)//D-(A-1)//(C*D)
  t=M-m 
  print(B-A+1-t)
  return 
main()

Submission status: Wrong Answer

Solution code:
import math

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

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

cnt = []

CD = int(C*D / gcd(C, D))

for i in [C, D, CD]:
    if i > B:
        cnt.append(0)
        continue
    first = math.ceil(A/i)*i
    if first > B:
        cnt.append(0)
        continue
    count = (B-first)//i + 1
    cnt.append(count)

ans = (B-A+1) - (cnt[0]+cnt[1]-cnt[2])

print(int(ans))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():

    lines = input()
    a, b, c, d = list(map(int, lines[0].split()))

    def gcd(a, b):

        r = a % b

        if r == 0:
            return int(b)
        
        return gcd(b, r)

    g = gcd(c, d)
    gcm = c * d / g

    c_in = int(b // c - (a-1)//c)
    d_in = int(b // d - (a-1)//d)
    cd_in = int(b // gcm - (a-1)//gcm)

    ans = int((b-a+1) - (c_in + d_in - cd_in))
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():

    lines = input()
    a, b, c, d = list(map(int, lines[0].split()))

    def gcd(a, b):

        r = a % b

        if r == 0:
            return int(b)
        
        return gcd(b, r)

    g = gcd(c, d)
    gcm = c * d / g

    c_in = int(b // c - (a-1)//c)
    d_in = int(b // d - (a-1)//d)
    cd_in = int(b // gcm - (a-1)//gcm)

    ans = int((b-a+1) - (c_in + d_in - cd_in))
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

def main():

    lines = input()
    a, b, c, d = list(map(int, lines[0].split()))

    def gcd(a, b):

        r = a % b

        if r == 0:
            return int(b)
        
        return gcd(b, r)

    g = gcd(c, d)
    gcm = c * d / g
    print(gcm)


    c_in = int(b // c - (a-1)//c)
    d_in = int(b // d - (a-1)//d)
    cd_in = int(b // gcm - (a-1)//gcm)
    
    ans = int((b-a+1) - (c_in + d_in - cd_in))
    print(ans)

main()

Submission status: Wrong Answer

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

def f(x):
  return x-(x+c-1)//c-(x+d-1)//d+(x+c*d-1)//(c*d)

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math

A,B,C,D = map(int, input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)


maru1 = B // C
maru2 = A // C

maru3 = B // D
maru4 = A // D

maru5 = B // lcm(C,D)
maru6 = A // lcm(C,D)

ans_tmp = ((maru1-maru2)+(maru3-maru4)) - (maru5-maru6)
ans = ((B-A)+1) - ans_tmp

print(ans)

Submission status: Wrong Answer

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

E = max(C, D)
while True:
    if E % min(C, D) == 0:
        break
    E += max(C, D)

print(B - A - (B-A)//C - (B-A)//D + (B-A)//E)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

lcm_=lcm(C,D)
answer=B-A+1-(B//C-A//C)-(B//D-A//D)+(B//lcm_-A//lcm_)
if A%C==0:
    answer-=1
if A%D==0:
    answer-=1
if answer<=-1:
    print(0)
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

lcm_=lcm(C,D)
answer=B-A+1-(B//C-A//C)-(B//D-A//D)+(B//lcm_-A//lcm_)
if A%C==0:
    answer-=1
if A%D==0:
    answer-=1
print(answer)

Submission status: Wrong Answer

Solution code:
import math


# def calc(n, c, d):
#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n / c +
              n / d - n / (c * d / math.gcd(c, d)))


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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math


# def calc(n, c, d):
#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(math.floor(n / c) +
              math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))


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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math


# def calc(n, c, d):
#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n // c +
              n // d - n // (c * d / math.gcd(c, d)))


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

    print(int(calc(b, c, d)-calc(a-1, c, d)))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math


# def calc(n, c, d):
#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n / c +
              n / d - n / (c * d / math.gcd(c, d)))

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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math


# def calc(n, c, d):
#     return n-(math.floor(n / c) +
#               math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))
def calc(n, c, d):
    return n-(n // c +
              n // d - n // (c * d / math.gcd(c, d)))

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

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math


def calc(n, c, d):
    return n-(math.floor(n / c) +
              math.floor(n / d) - math.floor(n / (c * d / math.gcd(c, d))))


def calc2(n, m):
    return n-(math.floor(n / m))


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

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


if __name__ == "__main__":
    main()