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())
lcm = C * D // math.gcd(C,D)
wari_A = (A-1) - ((A-1) // C + (A-1) // D - (A-1)//lcm)
wari_B = B - (B// C + B // D - B//lcm)
print(wari_B -wari_A)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

l = int(math.gcd(c,d) * c / math.gcd(c,d) * d / math.gcd(c,d))
#print(l)
x = b // c - a // c
y = b // d - a // d
z = b // l - a // l
if a % c == 0 or a % d == 0:
    print(int(b-a-(x+y-z)))
else:
    print(int(b-a-(x+y-z))+1)
#print(x,y,z)

Submission status: Runtime Error

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

p = math.floor((c * d) / math.gcd(c, d))

a_under = a-1

ans = (b - math.floor(b/c) - math.floor(b/d) + math.floor(b/p)) - (a_under - math.floor(a_under/c) - math.floor(a_under/d) + math.floor(a_under/p))

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

ans = 0
p = lcm(c, d)

a_under = a-1

ans = (b - math.floor(b/c) - math.floor(b/d) + math.floor(b/p)) - (a_under - math.floor(a_under/c) - math.floor(a_under/d) + math.floor(a_under/p))

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

ans = 0
p = lcm(c, d)

print(p)

a_under = a-1

ans = (b - math.floor(b/c) - math.floor(b/d) + math.floor(b/p)) - (a_under - math.floor(a_under/c) - math.floor(a_under/d) + math.floor(a_under/p))

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

ans = 0
p = lcm(c, d)

print(p)

a_under = a-1

ans = (b - math.floor(b/c) - math.floor(b/d) + math.floor(b/p)) - (a_under - math.floor(a_under/c) - math.floor(a_under/d) + math.floor(a_under/p))

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

ans = 0
p = lcm(c, d)

print(p)

a_under = a-1

ans = (b - b // c - b // d + b // p) - (a_under - a_under // c - a_under // d + a_under//p)

print(ans)

Submission status: Runtime Error

Solution code:
import math 
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
a,b,c,d = map(int, input().split())

cd = gcd(c,d)
cd = c*d //cd
c_able = b//c - (a-1)//c
d_able = b//d - (a-1)//d
cd_able = b//(cd) - (a-1)//(cd)

print(b- a + 1 - (c_able + d_able - cd_able))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//gcd(C, D) - (A-1)//math.gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
sc = B//C - (A-1)//C
sd = B//D - (A-1)//D
scd = B//(math.gcdC, D) - (A-1)//math.gcd(C, D)
print(sc, sd, scd, B-A+1)
print(B-A+1 - sc - sd + scd)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
b_c = b//c
b_d = b//d
a_c = (a-1)//c
a_d = (a-1)//d
b_cd = b//int((c*d)/math.gcd(c, d))
a_cd = (a-1)//int((c*d)/math.gcd(c, d))
print((b-a+1)-(b_c+b_d-b_cd-(a_c+a_d-a_cd)))

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
A,B,C,D = map(int,input().split())
import fractions
e = C * D
ans = 0
first = (((A-1) // 12)+1) * 12
last = (B // 12) * 12 
if last - first <= 0:
    for i in range(A,B+1):
        if i % C != 0 and i % D != 0:
            ans += 1
else:
    ans += (last-first) * (1-1/C) * (1-1/D)
    for i in range(A,first):
        if i % C != 0 and i % D != 0:
            ans += 1
    for j in range(last+1,B+1):
        if i % C != 0 and i % D != 0:
            ans += 1
print(int(ans))

Submission status: Runtime Error

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


#     {x | A <= x <= B and x % C != 0 and x % D != 0}
# =             {x | 1 <= x <= B and x % C != 0 and x % D != 0}
#           -   {x | 1 <= x <= A-1 and x % C != 0 and x % D != 0}
# =   {x | 1 <= x <= B} - {x | 1 <= x <= B and x % C = 0} - {x | 1 <= x <= B and x % D = 0} + - {x | 1 <= x <= B and x % C = 0 and x % D = 0}
#     (略)

def func(x,y):
    # print(x,y,math.floor((x/y)))
    return math.floor((x/y))

# print(func(100,10))

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

Submission status: Runtime Error

Solution code:
a,b,c,d = input()
count = 0
for i in range(a,b+1):
  if i % c == 0 or i % d == 0:
    continue
  count += 1

print(count)

Submission status: Runtime Error

Solution code:
import math

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

A -= 1
lcm = C // math.gcd(C, D) * D
ans = B - A

ans -= B // C
ans -= B // D
ans += B // lcm

ans += A // C
ans += A // D
ans -= A // lcm

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

A -= 1
lcm = C // gcd(C, D) * D
ans = B - A

ans -= B // C
ans -= B // D
ans += B // lcm

ans += A // C
ans += A // D
ans -= A // lcm

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

A -= 1
lcm = C * D // gcd(C, D)
ans = B - A

ans -= B // C
ans -= B // D
ans += B // lcm

ans += A // C
ans += A // D
ans -= A // lcm

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

A -= 1
lcm = C*D//gcd(C, D)
ans = B - A

ans -= B//C
ans -= B//D
ans += B//lcm

ans += A//C
ans += A//D
ans -= A//lcm

print(ans)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
def muri(n):
    return n - n//c - n//d + n//(c*d//math.gcd(c, d))

print(muri(b)-muri(a-1))

Submission status: Runtime Error

Solution code:
def lcm(x, y):
	""" 最小公倍数を求める """
    return (x * y) // math.gcd(x, y)

def q3():
    """ C - Anti-Division """
    import math
    A,B,C,D = (int(i) for i in input().split())

    num_C = B // C - (A - 1) // C  # Cで割り切れる個数
    num_D = B // D - (A - 1) // D  # Dで割り切れる個数
    lcm_CD = lcm(C, D)
    num_CD = B // lcm_CD - (A - 1) // lcm_CD  # CとDの最小公倍数で割り切れる個数
    
    num_all = num_C + num_D - num_CD  # 全ての割り切れる個数
    ans = B - A + 1 - num_all
    print(ans)

if __name__ == '__main__':
    q3()

Submission status: Runtime Error

Solution code:
def q3():
    """ C - Anti-Division """
    import math
    A,B,C,D = (int(i) for i in input().split())

    def lcm(x, y):
        """ 最小公倍数を求める """
        return (x * y) // math.gcd(x, y)

    num_C = B // C - (A - 1) // C  # Cで割り切れる個数
    num_D = B // D - (A - 1) // D  # Dで割り切れる個数
    num_CD = B // lcm(C, D) - (A - 1) // lcm(C, D)  # CとDの最小公倍数で割り切れる個数
    num_all = num_C + num_D - num_CD  # 全ての割り切れる個数
    ans = B - A + 1 - num_all
    print(ans)

if __name__ == '__main__':
    q3()

Submission status: Runtime Error

Solution code:
def q3():
    import math
    A,B,C,D = (int(i) for i in input().split())

    def lcm(x, y):
        """ 最小公倍数を求める """
        return (x * y) // math.gcd(x, y)

    num_C = B // C - (A - 1) // C  # Cで割り切れる個数
    num_D = B // D - (A - 1) // D  # Dで割り切れる個数
    num_CD = B // lcm(C, D) - (A - 1) // lcm(C, D)  # CとDの最小公倍数で割り切れる個数
    num_all = num_C + num_D - num_CD  # 全ての割り切れる個数
    ans = B - A + 1 - num_all
    print(ans)

if __name__ == '__main__':
    q3()

Submission status: Runtime Error

Solution code:
from gcd import fractions
a,b,c,d = map(int,input().split())
def l(x,y):
    return x*y//gcd(x,y)
U = b-a+1
s1 = b//c - (a-1)//c
s2 = b//d - (a-1)//d
s3 = b//l(a,b) - (a-1)//l(a,b)
print(U-(s1+s2-s3))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = list(map(int, input().split()))
cc = int(B/C) - int((A-1)/C)
dd = int(B/D) - int((A-1)/D)
cd = C*D / math.gcd(C,D)
ee = int(B/(cd)) - int((A-1)/(cd))
U = B-A+1
print(U - (cc + dd - ee))

Submission status: Runtime Error

Solution code:
from math import gcd
a, b, c, d = map(int, input().split())
"""
ans: (B-A) - {Cの倍数の個数＋Dの倍数の個数 - CDの倍数の個数}
"""
def count(t):
    amari = a % t
    return (b - a - amari ) // t
print( b-a - (count(c) + count(d) - count(c*d)))

Submission status: Runtime Error

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

bc = B // C 
bd = B // D
bcd = B // (C*D//math.gcd(C, D))
ans = B- (bc + bd - bcd)
ac = (A-1) // C
ad = (A-1) // D
acd = (A-1) //(C*D//math.gcd(C, D))
ans2=  A-1 - (ac + ad - acd)
ans = ans - ans2
print(ans)

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
def div_num(a, b, c):
    if (a%c)==0:
        return (b//c)-(a//c)+1
    else:
        return (b//c)-(a//c)
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
XC = div_num(A, B, C)
XD = div_num(A, B, D)
print("XC==={},  XD==={},  XCD==={}".format(XC,XD,XCD))
print(B-A+1-(XC+XD-XCD))

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
def div_num(a, b, c):
    if (a%c)==0:
        return (b//c)-(a//c)+1
    else:
        return (b//c)-(a//c)

XC = div_num(A, B, C)
XD = div_num(A, B, D)
XCD = div_num(A,B,int((C*D)/math.gcd(C,D)))
print(B-A+1-(XC+XD-XCD))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
div_c = B // C
div_d = B // D
cd = lcm(C, D)
div_cd = B // cd
B_ = B - (div_c + div_d - div_cd)

div_c2 = A // C
div_d2 = A // D
div_cd2 = A // cd
A_ = A - (div_c2 + div_d2 - div_cd2)

print(B_ - A_)

Submission status: Runtime Error

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

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

P=[c,d,lcm(c,d)]
A=[]
for p in P:
    if a%p==0:
        left=a//p
    else:
        left=a//p+1
    right=b//p
    if left<=right:
        A.append(right-left+1)
print(b-a+1-A[0]-A[1]+A[2])

Submission status: Runtime Error

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

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a
 #最小公倍数
def lcm(a,b):
    return a*b // gcd(a,b)

def calc_num(n, C, D):
    """
    0~Nまでで、C or Dで割り切れない数の個数
    """
    div_C = n//C
    div_D = n//D
    div_CD = n//(lcm(C, D))
    return n-div_C-div_D+div_CD


def solve():
    A, B, C, D = map(int, input().split())
    return calc_num(B, C, D)-calc_num(A-1, C, D)

print(solve())

Submission status: Runtime Error

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

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b = b,a%b
    return a
 #最小公倍数
def lcm(a,b):
    return a*b // gcd(a,b)

gcd_num = lcm(c,d)

def calc_num(n, C, D):
    """
    0~Nまでで、C or Dで割り切れない数の個数
    """
    div_C = n//C
    div_D = n//D
    div_CD = n//(lcm(C, D))
    return n-div_C-div_D+div_CD


def solve():
    A, B, C, D = map(int, input().split())
    return calc_num(B, C, D)-calc_num(A-1, C, D)

print(solve())

Submission status: Runtime Error

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

num = (C*D)//(math.gcd(C, D))
if(A%C==0):
    num1 = A//C-1
else:
    num1 = A//C
if(A%D==0):
    num2 = A//D-1
else:
    num2 = A//D
if(A%num == 0):
    num3 = A//num-1
else:
    num3 = A//num
print(int(B-A+1-((B//C-num1)+(B//D-num2)-(B//num-num3))))

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)

num = lcm(C, D)
if(A%C==0):
    num1 = A//C-1
else:
    num1 = A//C
if(A%D==0):
    num2 = A//D-1
else:
    num2 = A//D
if(A%num == 0):
    num3 = A//num-1
else:
    num3 = A//num
print(int(B-A+1-((B//C-num1)+(B//D-num2)-(B//num-num3))))

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd
import math

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

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

Submission status: Runtime Error

Solution code:
from functools import reduce
from fractions import gcd

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

N = B-A+1
print(N-(N//C+N//D-N//X))

Submission status: Runtime Error

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

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

def count(n):
    c = n//C
    d = n//D
    g = gcd(C, D)
    l = C*D//gcd
    return n -c -d +n//l

print(count(B) - count(A-1))

Submission status: Runtime Error

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

if A % C ==0:ca = A//C-1
else: ca = A//C
cb = B//C


if A % D ==0: ad = A//D-1
else:da = A//D 
db = B//D

lcm = C * D //gcd(C,D)
if A % lcm==0: cda = A//lcm-1
else:cda = A//lcm
cdb = B//lcm

print(B-A+1-((cb-ca)+(db-da)-(cdb-cda)))

Submission status: Runtime Error

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

l=C*D//math.gcd(C,D)
underB = B- (B//C+B//D-B//l)
underA = (A-1)- ((A-1)//C+(A-1)//D-(A-1)//l)
#print(underB, underA)
print(underB-underA)

Submission status: Runtime Error

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

Submission status: Runtime Error

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


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

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
C_wareru = B//C-(A-1)//C
D_wareru = B//D-(A-1)//D
def lcm(a,b):
    return ((a*b) // math.gcd(a,b))
CD = lcm(C,D)
CD_wareru = B//CD-(A-1)//CD
print(B-A+1-(C_wareru+D_wareru-CD_wareru))

Submission status: Runtime Error

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

def gcd(x, y):
    if x < y:
        x, y = y, x
    while a % b != 0:
        a, b = b, a % b

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

print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

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

print(ans)

Submission status: Runtime Error

Solution code:


A,B,C,D=[int(x) for x in input().rstrip().split()]
cnt=0

import math

def lcm(x, y):
  if x!=0 and y!=0:
    return (x * y) // math.gcd(x, y)
  else:
    return 0

    
baisuu=lcm(C,D)

u_A=(A-1)-(A-1)//C-(A-1)//D+(A-1)//baisuu

u_B=B-B//C-B//D+B//baisuu

print(u_B-u_A)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=[int(x) for x in input().rstrip().split()]
cnt=0


def lcm(x, y):
  if x!=0 and y!=0:
    return (x * y) // math.gcd(x, y)
  else:
    return 0

    
baisuu=lcm(C,D)

u_A=(A-1)-(A-1)//C-(A-1)//D+(A-1)//baisuu

u_B=B-B//C-B//D+B//baisuu

print(u_B-u_A)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=[int(x) for x in input().rstrip().split()]
cnt=0


def lcm(x, y):
  if x!=0 and y!=0:
    return (x * y) // math.gcd(x, y)
  else:
    return 0

    
baisuu=lcm(C,D)
yakusuu=math.gcd(C,D)

u_A=(A-1)-(A-1)//C-(A-1)//D+(A-1)//baisuu

u_B=B-B//C-B//D+B//baisuu

print(u_B-u_A)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=[int(x) for x in input().rstrip().split()]
cnt=0


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

    
baisuu=lcm(C,D)
yakusuu=math.gcd(C,D)

u_A=(A-1)-(A-1)//C-(A-1)//D+(A-1)//baisuu

u_B=B-B//C-B//D+B//baisuu

print(u_B-u_A)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=[int(x) for x in input().rstrip().split()]
cnt=0
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
baisuu=lcm(C,D)
yakusuu=math.gcd(C,D)

u_A=(A-1)-(A-1)//C-(A-1)//D+(A-1)//baisuu


u_B=B-B//C-B//D+B//baisuu
# for i in range(A,baisuu):
#   if i%C!=0 and i%D!=0:
#     cnt+=1

print(u_B-u_A)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=[int(x) for x in input().rstrip().split()]
cnt=0
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
baisuu=lcm(C,D)
yakusuu=math.gcd(C,D)

u_A=(A-1)-(A-1)//C-(A-1)//D+(A-1)//baisuu


u_B=B-B//C-B//D+B//baisuu
# for i in range(A,baisuu):
#   if i%C!=0 and i%D!=0:
#     cnt+=1

print(u_B-u_A)

Submission status: Runtime Error

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

c_count = b//c
d_count = b//d
# 最小公倍数で割る
c_d = b//(c*d//math.gcd(c, d))

print(b - c_count - d_count + c_d - (a-1 - (a-1)//c - (a-1)//d + (a-1)//(c*d//math.gcd(c, d))))

Submission status: Runtime Error

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

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

E=lcm(C,D)

num_C=B//C-(A-1)//C
num_D=B//D-(A-1)//D
num_CD=B//E-(A-1)//E

ans=(B-A+1)-(num_C+num_D-num_CD)
print(ans)

Submission status: Runtime Error

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

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

num_C=B//C-(A-1)//C
num_D=B//D-(A-1)//D
num_CD=B//E-(A-1)//E

ans=(B-A+1)-(num_C+num_D-num_CD)
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C,D=map(int,input().split())
ans=0
for i in range(A,B+1):
  if m%C!=0 and m%D!=0:
    ans=ans+1
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C,D=map(int,input().split())
ans=0
for i in range(A,B+1)
  if m%C!=0 and m%D!=0:
    ans=ans+1
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

A, B, C, D = map(int, input().split())
N = B - A + 1
lcm_CD = (C * D) // gcd(C, D)

sumB = B - B // C - B // D + B // lcm_CD
sumA = (A - 1) - (A - 1) // C - (A - 1) // D + (A - 1) // lcm_CD

print(sumB - sumA)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
all_val = b-a+1
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
if a%c == 0:
  c_val = b//c-a//c+1
else:
  c_val = b//c-a//c
if a%d == 0:
  d_val = b//d-a//d+1
else:
  d_val = b//d-a//d
if a%lcm(c,d) == 0:
  lcm_val = b//lcm(d,c)-a//lcm(d,c)+1
else:
  lcm_val = b//lcm(d,c)-a//lcm(d,c)
print(all_val-c_val-d_val+lcm_val)

Submission status: Runtime Error

Solution code:

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

#cとdの最小公倍数を求める(lcm = least common multiple)
lcm (c*d)/math.gcd(c,d)

ac = (A-1) // c
ad = (A-1) // d

bc = b // c
bd = b // d

ae = (A-1) // lcm
be = b // lcm

s = bc - ac
t = bd - ad
u = be - ae

print(b-a+1-s-t+u)

Submission status: Runtime Error

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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

Submission status: Runtime Error

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

import math

f=math.gcd(c,d)           #最大公約数
f2=c*d//f                          #最小公倍数

# a未満でcかdで割れるかず
a-=1
x = a//c
y = a//d
z = a//f2
ac = x+y-z

# b以下でcかdで割れるかず
x = b//c
y = b//d
z = b//f2
bc = x+y-z

print(b-a-(bc-ac))

Submission status: Runtime Error

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

#
c_d = c * d / fractoins.gcd(c, d)

def check(cc):
    if a%cc == 0:
        tmp_a = a
    else:
        tmp_a = cc*(a//cc+1)
    if b%cc == 0:
        tmp_b = b
    else:
        tmp_b = cc*(b//cc)

    #print('a, b')
    #print(tmp_a, tmp_b)
    if tmp_a > b:
        return 0
    elif tmp_b < a:
        return 0
    tmp = tmp_b-tmp_a

    return (tmp // cc) + 1

# c
tmp_1 = check(c)
#d
tmp_2 = check(d)

tmp_3 = check(c_d)


#print(tmp_1, tmp_2, tmp_3)

print(int((b-a)-(tmp_1+tmp_2-tmp_3*2)))

Submission status: Runtime Error

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

#
c_d = c * d / math.gcd(c, d)

def check(cc):
    if a%cc == 0:
        tmp_a = a
    else:
        tmp_a = cc*(a//cc+1)
    if b%cc == 0:
        tmp_b = b
    else:
        tmp_b = cc*(b//cc)

    #print('a, b')
    #print(tmp_a, tmp_b)
    if tmp_a > b:
        return 0
    elif tmp_b < a:
        return 0
    tmp = tmp_b-tmp_a

    return (tmp // cc) + 1

# c
tmp_1 = check(c)
#d
tmp_2 = check(d)

tmp_3 = check(c_d)


#print(tmp_1, tmp_2, tmp_3)


print(int((b-a)-(tmp_1+tmp_2-tmp_3*2)))

Submission status: Runtime Error

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

# 最小公倍数
c_d = c * d / math.gcd(c, d)

def check(cc):
    if a%cc == 0:
        tmp_a = a
    else:
        tmp_a = cc*(a//cc+1)
    if b%cc == 0:
        tmp_b = b
    else:
        tmp_b = cc*(b//cc)

    #print('a, b')
    #print(tmp_a, tmp_b)
    if tmp_a > b:
        return 0
    elif tmp_b < a:
        return 0
    tmp = tmp_b-tmp_a

    return (tmp // cc) + 1

# c
tmp_1 = check(c)
#d
tmp_2 = check(d)

tmp_3 = check(c_d)


#print(tmp_1, tmp_2, tmp_3)


print(int((b-a)-(tmp_1+tmp_2-tmp_3*2)))

Submission status: Runtime Error

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

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

c_min = a + (c - a % c) if (a % c) != 0 else a
c_max = b - b % c
d_min = a + (d - a % d) if (a % d) != 0 else a
d_max = b - b % d
e_min = a + (e - a % e) if (a % e) != 0 else a
e_max = b - b % e

n_c = (c_max - c_min) // c + 1 if c_min <= c_max else 0
n_d = (d_max - d_min) // d + 1 if d_min <= d_max else 0
n_e = (e_max - e_min) // e + 1 if e_min <= e_max else 0

ans = b - a + 1 - n_c - n_d + n_e

print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
zen=int(b-a)
c=int(zen//c)
d=int(zen//d)
kasa=int(zen/(c*d))

ans=zen-c-d+kasa

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

C_count = math.floor(B / C) - math.floor(A / C)
if (A % C) == 0:
    C_count += 1
D_count = math.floor(B / D) - math.floor(A / D)
if (A % D) == 0:
    D_count += 1
CD_count = math.floor(B / CD) - math.floor(A / CD)
if (A % CD) == 0:
    CD_count += 1

result = total - C_count - D_count + CD_count

print(result)

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = [int(i) for i in input().split()]
result = B+1 - A
def lcm(a, b):
    return (a * b) // math.gcd(a, b)
def wareru(min_num, max_num, waru):
    return (max_num)//waru - (min_num-1)//waru
result -= wareru(A, B, C) + wareru(A, B, D) - wareru(A, B, lcm(C,D))
print(result)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int, input().split())
for i in range(c,1,-1):#cから2まで
    if c % i == 0 and d % i == 0:
        s = i
        break
s = (c // s) * (d // s) * s
print(b - a + 1 - b//c + a//c - b//d + a//d + b//s - a//s)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int, input().split())
for i in range(c,1,-1):#cから2まで
    if c % i == 0 and d % i == 0:
        s = i
        break
s = (c // s) * (d // s) * s
print(s)
print(b - a + 1 - b//c + a//c - b//d + a//d + b//s - a//s)

Submission status: Runtime Error

Solution code:
import math

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

cd_gcd = math.gcd(c, d)
cd_lcm = c * d // cd_gcd

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

Submission status: Runtime Error

Solution code:
import math

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

cd_gcd = math.gcd(c, d)
cd_lcm = c * d // cd_gcd

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

Submission status: Runtime Error

Solution code:
A, B, C, D = map(int, input().split())
s = list(range(A, B + 1))
cnt = [-1] * 2 

for i in s:
    if i % C == 0 and cnt[0] == -1:
        cnt[0] = s.index(i)
    if i % D == 0 and cnt[1] == -1:
        cnt[1] = s.index(i)
    if cnt[0] != -1 and cnt[1] != -1:
        break

t = s[cnt[0] :: C]
u = s[cnt[1] :: D]

ans = len(s) - (len(set(t)) + len(set(u)) - len(set(t) & set(u)))
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
A, B, C, D = map(int, input().split())
s = np.array(list(range(A, B + 1)))
s = s[s % C != 0]
t = s[s % D != 0]
s = set(s)
t = set(t)
print(len(s & t))

Submission status: Runtime Error

Solution code:
import math

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

cnt = B//C -(A - 1)//C + B//D - (A - 1)//D - ((B//((C * D) // math.gcd(C, D))) - (A - 1)//((C * D) // math.gcd(C, D)))
cnt1 = B - (A - 1) -cnt

print(cnt1)

Submission status: Runtime Error

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


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


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


z = ((b+1) // e) - ((a+1) // e)


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

Submission status: Runtime Error

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

c = (B//C) - ((A-1)//C)
d = (B//D) - ((A-1)//D)
j = (B//x) - ((A-1)//x)

div = (c+d-j)
print(W-div)

Submission status: Runtime Error

Solution code:
from sys import stdin
from fractions import gcd

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

a, b, c, d = (int(x) for x in stdin.readline().rstrip().split())

lcm = lcm(c, d)

total = b - (a - 1)
mc = b // c - (a - 1) // c
md = b // d - (a - 1) // d
mlcm = b // e - (a - 1) // e

print(total - (mc + md - mlcm))

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd

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

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

length = b - a + 1
lc = a % c
rc = b % c
ld = a % d
rd = b % d
lcm = lcm(c, d)

ans = length
if (b < c) and (b < d):
    print(ans)
    sys.exit()

if length == c:
    ans -= length//c
if length == d:
    ans -= lenght//d

if length > c:
    temp = length//c
    if lc + rc >= c:
        temp += 1
    ans -= temp

if length > d:
    temp = length//d
    if ld + rd >= d:
        temp += 1
    ans -= temp

if length < c and ((lc > rc) or lc == 0 or rc == 0):
    ans -= 1
if length < d and ((ld > rd) or ld == 0 or rd == 0):
    ans -= 1

i = 1
while i * lcm <= b:
    if a <= i * lcm <= b:
        ans += 1
    i += 1

print(ans)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int,input().split())
A -= 1
g = math.gcd(C, D)
l = C * D / g

sA = A // C
eA = A // D
lA = A - (eA + sA) + A // l

sB = B // C
eB = B // D
lB = B - (eB + sB) + B // l
print(int(lB - lA))

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)
ans = b - a + 1
ans -= b // c - (a - 1) // c
ans -= b // d - (a - 1) // d
ans += b // (c * d) - (a - 1) // lcm(c, d)
print(ans)

Submission status: Runtime Error

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

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

k = b-a+1

amri_c = a % c
if amri_c == 0:
    amri_c = c
    k_c = (k - (amri_c - 1)) // c
else:
    k_c = (k - (amri_c - 1)) // c + 1

amri_d = a % d
if amri_d == 0:
    amri_d = d
    k_d = (k - (amri_d - 1)) // d
else:
    k_d = (k - (amri_d - 1)) // d + 1

amri_cd = a % lcm(c, d)
if amri_cd == 0:
    amri_cd = lcm(c, d)
    k_cd = (k - (amri_cd - 1)) // lcm(c, d)
else:
    k_cd = (k - (amri_cd - 1)) // lcm(c, d) + 1

ans = k-k_c-k_d+k_cd

print(ans)

Submission status: Runtime Error

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

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


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

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

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

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

print(ans)