Buggy python submission (verdict: Runtime Error):

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import math
f=math.gcd(C,D)
f2=C*D//f
#print(f2)

both=B//f2 - (A-1)//f2
#print('both', both)

#C
Ccount=B//C - (A-1)//C
#print('C', Ccount)

#D
Dcount=B//D - (A-1)//D
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Fixed submission:

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import fractions
f=fractions.gcd(C,D)
f2=C*D//f
#print(f2)

both=B//f2 - (A-1)//f2
#print('both', both)

#C
Ccount=B//C - (A-1)//C
#print('C', Ccount)

#D
Dcount=B//D - (A-1)//D
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Buggy python submission (verdict: Time Limit Exceeded):

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import fractions
f=fractions.gcd(C,D)
f2=C*D//f
#print(f2)

i=-1
flag=0
while True:
    i+=1
    if f2*i>=A and flag!=1:
        hajime=i
        flag=1
    elif f2*i>B:
        owari=i
        break
both=owari-hajime
#print('both', both)

#C
i=-1
flag=0
while True:
    i+=1
    if C*i>=A and flag!=1:
        hajime=i
        flag=1
    elif C*i>B:
        owari=i
        break
Ccount=owari-hajime
#print('C', Ccount)

#D
i=-1
flag=0
while True:
    i+=1
    if D*i>=A and flag!=1:
        hajime=i
        flag=1
    elif D*i>B:
        owari=i
        break
Dcount=owari-hajime
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Fixed submission:

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import fractions
f=fractions.gcd(C,D)
f2=C*D//f
#print(f2)

both=B//f2 - (A-1)//f2
#print('both', both)

#C
Ccount=B//C - (A-1)//C
#print('C', Ccount)

#D
Dcount=B//D - (A-1)//D
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Buggy python submission (verdict: Runtime Error):

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import math
f=math.gcd(C,D)
f2=C*D//f
#print(f2)

i=-1
flag=0
while True:
    i+=1
    if f2*i>=A and flag!=1:
        hajime=i
        flag=1
    elif f2*i>B:
        owari=i
        break
both=owari-hajime
#print('both', both)

#C
i=-1
flag=0
while True:
    i+=1
    if C*i>=A and flag!=1:
        hajime=i
        flag=1
    elif C*i>B:
        owari=i
        break
Ccount=owari-hajime
#print('C', Ccount)

#D
i=-1
flag=0
while True:
    i+=1
    if D*i>=A and flag!=1:
        hajime=i
        flag=1
    elif D*i>B:
        owari=i
        break
Dcount=owari-hajime
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Fixed submission:

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import fractions
f=fractions.gcd(C,D)
f2=C*D//f
#print(f2)

both=B//f2 - (A-1)//f2
#print('both', both)

#C
Ccount=B//C - (A-1)//C
#print('C', Ccount)

#D
Dcount=B//D - (A-1)//D
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Buggy python submission (verdict: Runtime Error):

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import math
f=math.gcd(C,D)
f2=C*D//f
#print(f2)

i=-1
flag=0
while True:
    i+=1
    if f2*i>=A and flag!=1:
        hajime=i
        flag=1
    elif f2*i>B:
        owari=i
        break
both=owari-hajime
#print('both', both)

#C
i=-1
flag=0
while True:
    i+=1
    if C*i>=A and flag!=1:
        hajime=i
        flag=1
    elif C*i>B:
        owari=i
        break
Ccount=owari-hajime
#print('C', Ccount)

#D
i=-1
flag=0
while True:
    i+=1
    if D*i>=A and flag!=1:
        hajime=i
        flag=1
    elif D*i>B:
        owari=i
        break
Dcount=owari-hajime
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Fixed submission:

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import fractions
f=fractions.gcd(C,D)
f2=C*D//f
#print(f2)

both=B//f2 - (A-1)//f2
#print('both', both)

#C
Ccount=B//C - (A-1)//C
#print('C', Ccount)

#D
Dcount=B//D - (A-1)//D
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Buggy python submission (verdict: Runtime Error):

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import math
f=math.gcd(C,D)
f2=C*D//f
#print(f2)

i=-1
flag=0
while True:
    i+=1
    if f2*i>=A and flag!=1:
        hajime=i
        flag=1
    elif f2*i>B:
        owari=i
        break
both=owari-hajime
#print('both', both)

#C
i=-1
flag=0
while True:
    i+=1
    if C*i>=A and flag!=1:
        hajime=i
        flag=1
    elif C*i>B:
        owari=i
        break
Ccount=owari-hajime
#print('C', Ccount)

#D
i=-1
flag=0
while True:
    i+=1
    if D*i>=A and flag!=1:
        hajime=i
        flag=1
    elif D*i>B:
        owari=i
        break
Dcount=owari-hajime
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))

Fixed submission:

[A,B,C,D] = list(map(int,input().split()))
#print(C,D)
#both
import fractions
f=fractions.gcd(C,D)
f2=C*D//f
#print(f2)

both=B//f2 - (A-1)//f2
#print('both', both)

#C
Ccount=B//C - (A-1)//C
#print('C', Ccount)

#D
Dcount=B//D - (A-1)//D
#print('D', Dcount)

print(B-A+1 -(Ccount+Dcount-both))