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: Runtime Error

Solution code:
import math

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

# CとDの最小公倍数算出
bi = C*D/math.gcd(D,C)

A-=1
Bbi =B//bi
Abi =A//bi
sa = Bbi -Abi
# print(B-A-sa)

Bc = B//C
Bd = B//D

Ac = A//C
Ad = A//D

print(int( B-A - ((Bc-Ac) + (Bd-Ad) - sa)  ))

Submission status: Runtime Error

Solution code:
import fanctions
A,B,C,D = list(map(int, input().split()))
a=(A-1)//C
b=B//C
c=(A-1)//D
d=B//D
g = C*D//fanctions.gcd(C,D)
e=(A-1)//(g)
f=B//(g)

print(B-A+1 - (b-a) - (d-c) + (f-e))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = list(map(int, input().split()))
a=(A-1)//C
b=B//C
c=(A-1)//D
d=B//D
g = C*D//math.gcd(C,D)
e=(A-1)//(g)
f=B//(g)

print(B-A+1 - (b-a) - (d-c) + (f-e))

Submission status: Runtime Error

Solution code:
import math

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


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


a1 = a - 1
div_a = (a1 // c) + (a1 // d) - (a1 // lcm(c, d))
div_b = (b // c) + (b // d) - (b // lcm(c, d))

print((b - a + 1) - (div_b - div_a))

Submission status: Runtime Error

Solution code:
import math

entrada = list(map(int,input().split(" ")))

rangoMenor = entrada[0]
rangoMayor = entrada[1]
divisor1 = entrada[2]
divisor2= entrada[3]


multiplo = divisor2*divisor1// math.gcd(divisor1,divisor2)
cantidad = rangoMayor-rangoMenor
repetidos = rangoMayor//multiplo - rangoMenor//multiplo

if rangoMenor%divisor1==0:
	divisibles1 = rangoMayor//divisor1 +1 - rangoMenor//divisor1
else:
	divisibles1 = rangoMayor // divisor1 - rangoMenor//divisor1

divisibles2 = rangoMayor//divisor2 - rangoMenor//divisor2

resultado = cantidad -(divisibles1+divisibles2) +repetidos + 1
print(resultado)

Submission status: Runtime Error

Solution code:
import math
def div(A,B,C):
    n1=A%C
    if n1==0:
        ans1=A//C
    else:
        ans1=A//C+1
    n2=B%C
    if n2==0:
        ans2=B//C
    else:
        ans2=(B-B%C)//C
    d=ans2-ans1+1
    if d>=1:
        ans3=d
    else:
        ans3=0
    return ans3

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

Submission status: Runtime Error

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

rng=b-a+1
x=b//c-(a-1)//c
y=b//d-(a-1)//d
z=b//e-(a-1)//e
print(rng-x-y+z)

Submission status: Runtime Error

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

x = b//c - (a-1)//c
y = b//d - (a-1)//d
z = b//l - (a-1)//l
s = int(x+y-z)

print(b-a+1-s)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math


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


def main():
    A, B, C, D = [int(x) for x in stdin.readline().rstrip().split()]

    C_D_lcm = lcm(C, D)

    z = B//C_D_lcm - A//C_D_lcm

    if A % C == 0:
        x = (B//C)+1 - (A//C)
    else:
        x = (B//C) - A//C

    y = B//D - A//D

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

    dividable_by_c = b // c - (a-1) // c
    dividable_by_d = b // d - (a-1) // d
    lcm = c * d // fractions.gcd(c,d)
    dividable_by_c_and_d = b // lcm - (a-1) // lcm

    result = (b - a + 1) - dividable_by_c - dividable_by_d + dividable_by_c_and_d
    print(result)
resolve()

Submission status: Runtime Error

Solution code:
from fractions import gcd
from math import ceil,floor

(A,B,C,D)=( int ( x ) for x in input().split(" ") )
E = int ( C * D / fractions.gcd(C,D) )

print ( B - A - ( floor  ( B/C ) - ceil ( A/C ) + floor  ( B/D ) - ceil ( A/D ) + 1 - floor  ( B/E ) + ceil ( A/E ) - 1 ) )

Submission status: Runtime Error

Solution code:
from fractions import gcd
from math import ceil,floor

(A,B,C,D)=( int ( x ) for x in input().split(" ") )
E = int ( C * D / fractions.gcd(C,D) )

print ( B - A - ( math.floor  ( B/C ) - math.ceil ( A/C ) + math.floor  ( B/D ) - math.ceil ( A/D ) + 1 - math.floor  ( B/E ) + math.ceil ( A/E ) - 1 ) )

Submission status: Runtime Error

Solution code:
from fractions import gcd
from math import ceil,floor

(A,B,C,D)=( int ( x ) for x in input().split(" ") )
E = int ( C * D / fractions.gcd(C,D) )

print ( B - A - ( fractions.floor  ( B/C ) - fractions.ceil ( A/C ) + fractions.floor  ( B/D ) - fractions.ceil ( A/D ) + 1 - fractions.floor  ( B/E ) + fractions.ceil ( A/E ) - 1 ) )

Submission status: Runtime Error

Solution code:
import math
(A,B,C,D)=( int ( x ) for x in input().split(" ") )
E = int ( C * D / math.gcd(C,D) )

print ( B - A - ( math.floor  ( B/C ) - math.ceil ( A/C ) + math.floor  ( B/D ) - math.ceil ( A/D ) + 1 - math.floor  ( B/E ) + math.ceil ( A/E ) - 1 ) )

Submission status: Runtime Error

Solution code:
import math

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

x = math.gcd(C, D)
CD = x * (C // x) * (D // x)

Cm = B // C - (A - 1) // C
Dm = B // D - (A - 1) // D
CDm = B // CD - (A - 1) // CD

print(B + 1 - A - (Cm + Dm - CDm))

Submission status: Runtime Error

Solution code:
from math import gcd

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


def solve(a, b, c, d):
    div = ((b//c) - ((a-1)//c)) + ((b//d) - ((a-1)//d)) - ((b//lcm(c,d)) -
            ((a-1)//lcm(c,d))) 

    return (b - a + 1) - div

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

Submission status: Runtime Error

Solution code:
import math


def solve():
    a, b, c, d = map(int, input().split())
    lcm = c * d // math.gcd(c, d)
    div_c = b // c - (a - 1) // c
    div_d = b // d - (a - 1) // d
    div_cd = b // lcm - (a - 1) // lcm
    return (b - a + 1) - div_c - div_d + div_cd


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
import math


def solve():
    a, b, c, d = map(int, input().split())
    lcm = c * d // math.gcd(c, d)
    num_b = b - b // c - b // d + b // lcm
    a -= 1
    num_a = a - a // c - a // d + a // lcm
    return num_b - num_a


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
import math


def solve():
    a, b, c, d = map(int, input().split())
    lcm = c * d // math.gcd(c, d)
    num_b = b - b // c - b // d + b // lcm
    num_a = a - 1 - (a - 1) // c - (a - 1) // d + (a - 1) // lcm
    return num_b - num_a


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
import math


def solve():
    a, b, c, d = map(int, input().split())
    lcm = c * d // math.gcd(c, d)
    b_c = b // c
    b_d = b // d
    b_cd = b // lcm
    a_c = (a - 1) // c
    a_d = (a - 1) // d
    a_cd = (a - 1) // lcm
    return b - b_c - b_d + b_cd - (a - 1 - a_c - a_d + a_cd)


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
import math
a, b , c, d = map(int, input().split())
def num_cm(a, b, m):
    if a % m == 0:
        return (b//m) - (a//m) + 1 
    else:
        return (b//m) - (a//m)
lcm = (c * d) // math.gcd(c, d)
ans =  b - a + 1 - num_cm(a, b, c) - num_cm(a, b, d) + num_cm(a, b, lcm)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def main():
    cd = c * d / math.gcd(c, d)
    print(b - a - (f(c) + f(d) - f(cd)) + 1)

def f(x):
    return math.floor((b - x * math.ceil(a / x)) / x) + 1

main()

Submission status: Runtime Error

Solution code:
import math

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

# cとdの最大公約数
g = math.gcd(c, d)

# cとdの最小公倍数
l = c * d // g

# cとdで割り切れないb以下の数の個数
# (全体) - (cの倍数の個数) - (dの倍数の個数) + (cの倍数かつdの倍数の個数)
x = b - b // c - b // d + b // l

# cとdで割り切れない(a-1)以下の数の個数
y = (a - 1) - (a - 1) // c - (a - 1) // d + (a - 1) // l
    
print(x - y)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)
import math
def lcm(a,b):
    return a*b//math.gcd(a,b)


def div(n,divn):
    #1からnまでの中で、divnで割り切れる数の数を示す
    return n//divn

def divor(n,div1,div2):
    #1からnまでの中で、div1,div2のどちらかで割り切れる数の数を示す
    return div(n,div1)+div(n,div2)-div(n,lcm(div1,div2))
def nondivor(n,div1,div2):
    #１からnまでの中で、div1,div2のどちらでも割り切れない数の数を示す
    return n-divor(n,div1,div2)


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


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

Submission status: Runtime Error

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


def div(n,divn):
    #1からnまでの中で、divnで割り切れる数の数を示す
    return n//divn

def divor(n,div1,div2):
    #1からnまでの中で、div1,div2のどちらかで割り切れる数の数を示す
    return div(n,div1)+div(n,div2)-div(n,lcm(div1,div2))
def nondivor(n,div1,div2):
    #１からnまでの中で、div1,div2のどちらでも割り切れない数の数を示す
    return n-divor(n,div1,div2)


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


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

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(10000000)

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


def div(n,divn):
    #1からnまでの中で、divnで割り切れる数の数を示す
    return n//divn

def divor(n,div1,div2):
    #1からnまでの中で、div1,div2のどちらかで割り切れる数の数を示す
    return div(n,div1)+div(n,div2)-div(n,lcm(div1,div2))
def nondivor(n,div1,div2):
    #１からnまでの中で、div1,div2のどちらでも割り切れない数の数を示す
    return n-divor(n,div1,div2)


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


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

Submission status: Runtime Error

Solution code:
import math
def lcm(a,b):
    return int(a*b/math.gcd(a,b))


def div(n,divn):
    #1からnまでの中で、divnで割り切れる数の数を示す
    return n//divn

def divor(n,div1,div2):
    #1からnまでの中で、div1,div2のどちらかで割り切れる数の数を示す
    return div(n,div1)+div(n,div2)-div(n,lcm(div1,div2))
def nondivor(n,div1,div2):
    #１からnまでの中で、div1,div2のどちらでも割り切れない数の数を示す
    return n-divor(n,div1,div2)


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


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

Submission status: Runtime Error

Solution code:
import math

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


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


def ans(x):
    can_div_c_count = x // c
    can_div_d_count = x // d
    can_div_lcm_count = x // lcm(c, d)
    return x - (can_div_c_count + can_div_d_count - can_div_lcm_count)


print(ans(b)-ans(a))

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int, input().split())
li = list(range(a,b+1))
start1 = 0
start2 = 0
start3 = 0
for i in li:
    if i%c == 0:
        start1 = li.index(i)
        break
for j in li:
    if j%d == 0:
        start2 = li.index(j)
        break
for k in li:
    if k%(c*d)==0:
        start3 = li.index(k)
        break

print(b+1-a+len(li[start3::c*d])-len(li[start2::d])-len(li[start1::c]))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
c_min=0
d_min=0
cd_min=0
c_max=0
d_max=0
cd_max=0
cd=(c*d)//math.gcd(c,d)

c_min=a%c
c_max=b%c
d_min=a%d
d_max=b%d
cd_min=a%cd
cd_max=b%cd


countc=(b-c_max-a+c_min+1)//c
countd=(b-d_max-a+d_min+1)//d
countcd=(b-cd_max-a+cd_min+1)//cd
print(b-a+1-countc-countd+countcd)

Submission status: Runtime Error

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

GcdCD = math.gcd(C,D)
LcmCD = (C*D)//GcdCD

s1 = B- ((B//C)+(B//D)-(B//LcmCD))
s2 = (A-1)-(((A-1)//C)+((A-1)//D)-((A-1)//LcmCD))
if s2 < 0:
    s2 = 0
print(s1-s2)

Submission status: Runtime Error

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


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

b_cnt1 = b // c

b_cnt2 = b // d

b_cnt3 = b // lcm(c, d)

a_cnt1 = a // c

a_cnt2 = a // d

a_cnt3 = a // lcm(c, d)

print(b - (b_cnt1 + b_cnt2 - b_cnt3) - (a - (a_cnt1 + a_cnt2 - a_cnt3)))

Submission status: Runtime Error

Solution code:
import math

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

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

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

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = (int(i) for i in input().split())
C_div = int(0)
D_div = int(0)
CandD_div = int(0)
E =int(C*D/math.gcd(C,D))

if A%C == 0:
    C_div = int(B/C) - int(A/C) + 1
else:
    C_div = int(B/C) - int(A/C)

if A%D == 0:
    D_div = int(B/D) - int(A/D) + 1
else:
    D_div = int(B/D)- int(A/D)


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


ans = B - A + 1 - (C_div + D_div - CandD_div)
print(ans)

Submission status: Runtime Error

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

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

def slove(x, y, z):
	return ans = (x//y) + (x//z) - (x//lcm(y,z))
print(slove(b,c,d) - slove(a-1,c,d))

Submission status: Runtime Error

Solution code:
import math


def count_multiple(A, B, x):
    min_value = math.ceil(A / x)
    max_value = B // x
    
    return max_value - min_value + 1


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

lcm = C * D // math.gcd(C, D)
cnt = 0
for i, x in enumerate([C, D, lcm]):
    if i < 2:
        cnt += count_multiple(A, B, x)
    else:
        cnt -= count_multiple(A, B, x)

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

Submission status: Runtime Error

Solution code:
import math

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

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

mc = B//C - (A-1)//C
md = B//D - (A-1)//D
mcd = B//lcm(C,D) - (A-1)//lcm(C,D)

print(B-A+1-mc-md+mcd)

Submission status: Runtime Error

Solution code:
import math

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

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

mc = B//C - A//C
if A%C == 0:
    mc += 1
md = B//D - A//D
if A%D == 0:
    mc += 1

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

print(B-A+1-mc-md+mcd)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
A, B, C, D = map(int, input().split())
ans = 0
Am = 0
Bm = 0
df = 0

Am = A - (A // C + A // D - A //lcm(C,D))
Bm = B - (B // C + B // D - B //lcm(C,D))
ans = Bm - Am

if A % C != 0 and A % D != 0:
	ans += 1
print(ans)

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

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
A, B, C, D = map(int, input().split())
ans = 0
Am = 0
Bm = 0
df = 0

Am = A - (A // C + A // D - A //lcm_base(C,D))
Bm = B - (B // C + B // D - B //lcm_base(C,D))
ans = Bm - Am

if A % C != 0 and A % D != 0:
	ans += 1
print(ans)

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math

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

A, B, C, D = map(int, input().split())
ans = 0
Am = 0
Bm = 0
df = 0

Am = A - (A // C + A // D - A //lcm_base(C,D))
Bm = B - (B // C + B // D - B //lcm_base(C,D))
ans = Bm - Am

if A % C != 0 and A % D != 0:
	ans += 1
print(ans)

Submission status: Runtime Error

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

def diff(i, j, k):
	return (j // k) - ( i // k)

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

zedd = diff(a, b+1, c) + diff(a, b+1, d) - diff(a, b+1, lcm(c,d))
ans = (b-a+1) -zedd

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
[a,b,c,d]=[int(x) for x in input().split()]
k=(c*d)//gcd(c,d)
count=(b-a+1)-((b//c-(a-1)//c)+(b//d-(a-1)//d)-(b//k-(a-1)//k))
print(count)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int, input().split())
lis = list(range(a,b+1))
ans = 0

for i in lis:
	if i % c == 0:
		ans += 1
	elif i % d == 0:
		ans += 1
	else:
		pass
print(len(lis) - ans)

Submission status: Runtime Error

Solution code:
import math

n=[int(x) for x in input().split()]

a=(n[0]-1)//n[2]
b=(n[0]-1)//n[3]
c=(n[0]-1)//(n[2]*n[3]/math.gcd(n[2],n[3]))

d=n[1]//n[2]
e=n[1]//n[3]
f=n[1]//(n[2]*n[3]/math.gcd(n[2],n[3]))

print((n[1]-d-e+f)-((n[0]-1)-a-b+c))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import math

def count_antidivision(n, x, y):
    """
    returns count of numbers from 1 to n which are not dividable by x nor y.
    """
    return n - n // x - n // y + n // (x * y // math.gcd(x, y))    

def main(A, B, C, D):
    return count_antidivision(B, C, D) - count_antidivision(A-1, C, D)

if __name__ == '__main__':
    A, B, C, D = list(map(int, input().split()))
    print(main(A, B, C, D))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
import math

def count_antidivision(n, x, y):
    """
    returns count of numbers from 1 to n which are not dividable by x nor y.
    """
    return n - n // x - n // y + n // (x * y // math.gcd(x, y))    

def main(A, B, C, D):
    return count_antidivision(B, C, D) - count_antidivision(A-1, C, D)

if __name__ == '__main__':
    A, B, C, D = list(map(int, input().split()))
    print(main(A, B, C, D))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

li = list(range(a, b))

count = 0
for i in li:
  if i%c != 0 and i%d != 0:
    count += 1

print(count)

Submission status: Runtime Error

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

li = [a..b]

count = 0
for i in li:
  if i%c != 0 and i%d != 0:
    count += 1

print(count)

Submission status: Runtime Error

Solution code:
A,B,C,D = map(int,input().split())
 
def gcd( x, y ):
    while y != 0:
        x, y = y, x%y

ctr = 0

tmp1 = A // C
tmp2 = A // D
tmp3 = B // (C * D / gcd(C,D))
tmp4 = B // C
tmp5 = B // D

print(tmp4 + tmp5 - tmp3 - tmp1 -tmp2)

Submission status: Runtime Error

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


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

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
cd=b//lcm-(a-1)//lcm

print((b-a+1)-(cc+dd-cd))

Submission status: Runtime Error

Solution code:
import math

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

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
ee=b//(c * d // math.gcd(c, d))-(a-1)//(c * d // math.gcd(c, d))
    
print(cc,dd,ee)
print((b-a+1)-(cc+dd-ee))

Submission status: Runtime Error

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

ans = 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))))  

print(ans)

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
 
A,B,C,D = (int(i) for i in input().split()) 
X=lcm(C,D)
c=int((B-A+1)/C)
d=int((B-A+1)/D)
x=int((B-A+1)/X)
print(B-A-c-d+x)

Submission status: Runtime Error

Solution code:
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
 
A,B,C,D = (int(i) for i in input().split()) 
X=lcm(C,D)
c=int((B-A+1)/C)
d=int((B-A+1)/D)
x=int((B-A+1)/X)
print(B-A+1-c-d+x)

Submission status: Runtime Error

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

A,B,C,D = (int(i) for i in input().split()) 
X=lcm(C,D)
c=int((B-A+1)/C)
d=int((B-A+1)/D)
x=int((B-A+1)/X)

print(c+d-x)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

c_min = (a-1) // c
c_max = b // c
c_count = c_max - c_min

d_min = (a-1) // d
d_max = b // d
d_count = d_max - d_min

cd_min = (a-1) // (c * d // math.gcd(c, d))
cd_max = b // (c * d // math.gcd(c, d))
cd_count = cd_max - cd_min

print(b - (a-1) - c_count - d_count + cd_count)

Submission status: Runtime Error

Solution code:
import math
import fractions
l, r, p1, p2 = list(map(int, input().split()))
lcm = p1*p2 // fractions.gcd(p1, p2)
ans = (r-l+1) - (r//p1-(l-1)//p1) - (r//p2)-(l-1)//p2) + (r//lcm)-(l-1)//lcm
print(ans)

Submission status: Runtime Error

Solution code:
import math
l, r, p1, p2 = list(map(int, input().split()))
lcm = int(p1*p2 / math.gcd(p1, p2))
ans = (r-l+1) - (math.floor(r/p1)-math.ceil(l/p1)+1) - (math.floor(r/p2)-math.ceil(l/p2)+1) + math.floor(r/lcm)-math.ceil(l/lcm)+1
print(ans)

Submission status: Runtime Error

Solution code:
import math
from fractions import gcd

l, r, p1, p2 = list(map(int, input().split()))
lcm = int(l*r / gcd(p1, p2))
ans = (r-l+1) - (math.floor(r/p1)-math.ceil(l/p1)+1) - (math.floor(r/p2)-math.ceil(l/p2)+1) + math.floor(r/lcd)-math.ceil(l/lcd)+1
print(ans)

Submission status: Runtime Error

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

def lcm(x, y):
    return (x * y) / math.gcd(x, y)
E = lcm(C, D)

u = np.arange(A,B+1)
count_U = len(u)
u_c = [i for i in u if i % C == 0]
count_C = len(u_c)
u_d = [i for i in u if i % D == 0]
count_D = len(u_d)
u_e = [i for i in u if i % E == 0]
count_E = len(u_e)

answer = count_U - (count_C + count_D -count_E)
print(answer)

Submission status: Runtime Error

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

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
E = lcm(C, D)

u = np.arange(A,B+1)
count_U = len(u)
u_c = [i for i in u if i % C == 0]
count_C = len(u_c)
u_d = [i for i in u if i % D == 0]
count_D = len(u_d)
u_e = [i for i in u if i % E == 0]
count_E = len(u_e)

answer = count_U - (count_C + count_D -count_E)
print(answer)

Submission status: Runtime Error

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

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
E = lcm(C, D)

u = np.arange(A,B+1)
count_U = len(u)
u_c = [i for i in u if i % C == 0]
count_C = len(u_c)
u_d = [i for i in u if i % D == 0]
count_D = len(u_d)
u_e = [i for i in u if i % E == 0]
count_E = len(u_e)

answer = count_U - (count_C + count_D -count_E)
print(u)
print(u_c)
print(count_C)
print(u_d)
print(count_D)
print(u_e)
print(count_E)
print(answer)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math

def my_lcm(a: int, b: int):
    return int( abs(a*b) / math.gcd(a, b))

def nr_divide(a: int, b: int, x: int):
    return int(math.floor(b/x)) - int(math.ceil(a/x)) + 1

def solve(A: int, B: int, C: int, D: int):
    E = my_lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    count = N - nrC - nrD + nrE
    print(count)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math

def my_lcm(a: int, b: int):
    return int( abs(a*b) / math.gcd(a, b))

def nr_divide(a: int, b: int, x: int):
    return (int(math.floor(b/x)) - int(math.ceil(a/x))) + 1

def solve(A: int, B: int, C: int, D: int):
    E = my_lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    print(N - nrC - nrD + nrE)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)
    return

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math

def my_lcm(a: int, b: int):
    return int( abs(a*b) / math.gcd(a, b))

def nr_divide(a: int, b: int, x: int):
    return (int(math.floor(b/x)) - int(math.ceil(a/x))) + 1

def solve(A: int, B: int, C: int, D: int):
    E = my_lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    print(N - nrC - nrD + nrE)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math

def my_lcm(a: int, b: int):
    return abs(a*b) // math.gcd(a, b)

def nr_divide(a: int, b: int, x: int):
    return (int(math.floor(b/x)) - int(math.ceil(a/x))) + 1

def solve(A: int, B: int, C: int, D: int):
    E = my_lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    print(N - nrC - nrD + nrE)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math

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

def nr_divide(a: int, b: int, x: int):
    return (int(math.floor(b/x)) - int(math.ceil(a/x))) + 1

def solve(A: int, B: int, C: int, D: int):
    E = lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    print(N - nrC - nrD + nrE)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
import math

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

def nr_divide(a: int, b: int, x: int):
    return (b // x - int(math.ceil(a/x))) + 1

def solve(A: int, B: int, C: int, D: int):
    E = lcm(C, D)
    N = B - A + 1
    nrC = nr_divide(A, B, C)
    nrD = nr_divide(A, B, D)
    nrE = nr_divide(A, B, E)
    print(N - nrC - nrD + nrE)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:

import math

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

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

res_b = b - b // c - b // d + b // cd
a -= 1
res_a = a - a // c - a // d + a // cd


print(res_b - res_a)

Submission status: Runtime Error

Solution code:
import fractions

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

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

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

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

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

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

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

Submission status: Runtime Error

Solution code:
import math

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

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

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

print((b - b_c - b_d + b_cd) - ((a - 1) - a_c - a_d + a_cd))

Submission status: Runtime Error

Solution code:
temp=input().split()
A=int(temp[0])
B=int(temp[1])
C=int(temp[2])
D=int(temp[3])

for i in range(A, B+1):
  if i%C==0 and i%D==0:
    counter+=1
    
print(counter)

Submission status: Runtime Error

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

nc = int(b/c) - int((a-1)/c)
# print(nc)

nd = int(b/d) - int((a-1)/d)
# print(nd)

import math 

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

ncd = int(b/lcm(c,d)) - int((a-1)/lcm(c,d))
# print(ncd)

u = b - a + 1
# print(u)

ans = u - nc - nd + ncd

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

c_n = (b // c) - ((a - 1) // c)
d_n = (b // d) - ((a - 1) // d)

lcm = (c * d) // math.gcd(c, d)
lcm_n = (b // lcm) - ((a - 1) // lcm)

ans = (b - a + 1) - (c_n + d_n - lcm_n)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

print(k-count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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