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:
a, b, c, d = [int(e) for e in input().split()]

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

def f(a, b, n):
  x = (a // n) * n
  if x < a:
    x += n
  if x > b:
    return 0
  result = 0
  if a <= x <= b:
    result += 1
  result += (b - x) // n
  return result

acc = 0
acc += f(a, b, c)
acc += f(a, b, d)
acc -= f(a, b, gcd(c * d))
print(b - a + 1 - acc)

Submission status: Runtime Error

Solution code:
#ABC131 C
import math

A, B, C, D = map(int, input().split())
def ad(X):
    XmodC = X // C
    XmodD = X // D
    CD_lcm = C * D / math.gcd(C, D)
    XmodCD = X // CD_lcm
    return X - int(XmodC + XmodD - XmodCD)
ans = int(ad(B) - ad(A - 1))
print(ans)

Submission status: Runtime Error

Solution code:
#ABC131 C
import math

A, B, C, D = map(int, input().split())
def ad(X):
    XmodC = X // C
    XmodD = X // D
    CD_lcm = C * D / math.gcd(C, D)
    XmodCD = X // CD_lcm
    return X - int(XmodC + XmodD - XmodCD)
print(ad(B) - ad(A - 1))

Submission status: Runtime Error

Solution code:
#ABC131 C
import math

A, B, C, D = (int(_) for _ in input().split())
def ad(X):
    XmodC = X // C
    XmodD = X // D
    CD_lcm = C * D / math.gcd(C, D)
    XmodCD = X // CD_lcm
    return X - int(XmodC + XmodD - XmodCD)
print(ad(B) - ad(A - 1))

Submission status: Runtime Error

Solution code:
#ABC131 C
import math
A, B, C, D = (int(_) for _ in input().split())
def ad(X):
    XmodC = X // C
    XmodD = X // D
    CD_lcm = C * D / math.gcd(C, D)
    XmodCD = X // CD_lcm
    return X - (XmodC + XmodD - XmodCD)
print(int(ad(B) - ad(A - 1)))

Submission status: Runtime Error

Solution code:
#ABC131 C
import math
A, B, C, D = (int(_) for _ in input().split())
ABmodC = B // C - A // C
ABmodD = B // D - A // D
CD_lcm = C * D / math.gcd(C, D)
ABmodCD = B // CD_lcm - A // CD_lcm
print(int(ABmodC + ABmodD - ABmodCD))

Submission status: Runtime Error

Solution code:
import math

def lcm(p,q):
    return (p*q) // math.gcd(p,q)

def g(x,k):
    return x // k

def f(x,c,d):
    return x - (g(x,c)+g(x,d)-g(x,lcm(c,d)))

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

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

Submission status: Runtime Error

Solution code:

import math
(a, b, c, d) = [int(i) for i in input().split()]
c_d_lcm = (c * d) // math.gcd(c, d)
able_c_div = (b - a) // c
able_d_div = (b - a) // d
able_c_d_div = (b - a) // c_d_lcm
diff = b - a
print(diff - (able_c_div + able_d_div - able_c_d_div))

Submission status: Runtime Error

Solution code:
import numpy as np

W, H, x, y = [int(x) for x in input().split(" ")]
max_area =  W * H / 2.0
eps = 1e-6
if x + x = W and y + y == H:
    flag = 1
else:
    flag = 0

print(max_area, flag)

Submission status: Runtime Error

Solution code:
import numpy as np
from math.fraction import gcd

def lcm(x, y):
    return x * y // gcd(x, y)
A, B, C, D = [int(x) for x in input().split(" ")]
n_targets = B - A + 1

n_compC = n_targets - (B // C - (A - 1) // C)
n_compD = n_targets - (B // D - (A - 1) // D)
n_compCandD = n_targets - (B // lcm(C, D) - (A - 1) // lcm(C, D))

print(n_compC + n_compD - n_compCandD)

Submission status: Runtime Error

Solution code:
import numpy as np
import math

def lcm(x, y):
    return x * y // math.gcd(x, y)
A, B, C, D = [int(x) for x in input().split(" ")]
n_targets = B - A + 1

n_compC = n_targets - (B // C - (A - 1) // C)
n_compD = n_targets - (B // D - (A - 1) // D)
n_compCandD = n_targets - (B // lcm(C, D) - (A - 1) // lcm(C, D))

print(n_compC + n_compD - n_compCandD)

Submission status: Runtime Error

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

ans = int(0)
for x in range(a,b):
  if x%c!=0 andx%d!=0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math


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

    C_D = (C * D) // math.gcd(C, D)

    z = B//C_D - A//C_D

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

    # y = B//D - A//D

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

    print(A, B, C, D)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
import math


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

    C_D = (C * D) // math.gcd(C, D)

    z = B//C_D - A//C_D

    if A % C == 0:
        x = (B//C) - (A//C) + 1
    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:
from sys import stdin
import math


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

    C_D = (C * D) // math.gcd(C, D)

    z = B//C_D - A//C_D

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

    y = B//D - A//D

    # print(x, y, z)

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
import math


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

    C_D_gcd = (C * D) // math.gcd(C, D)

    z = B//C_D_gcd - A//C_D_gcd

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

    y = B//D - A//D

    # print(x, y, z)

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


if __name__ == "__main__":
    main()

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_gcd = lcm(C, D)

    z = B//C_D_gcd - A//C_D_gcd

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

    y = B//D - A//D

    # print(x, y, z)

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


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

bc = B // C
bd = B // D
bcd = B // cd
ac = (A - 1) // C
ad = (A - 1) // D
acd = (A - 1) // cd

bdiv = bc + bd - bcd
adiv = ac + ad - acd

alldiv = bdiv - adiv

ans = B - A + 1 - alldiv

print(int(ans))

Submission status: Runtime Error

Solution code:
A, B, C, D = [int(_) for _ in input().split()]

import math
def dvi_num(b, c):
    return math.floor(b / c)

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

def dvi_num2(b, c, d):
    return b - dvi_num(b,c) - dvi_num(b,d) + dvi_num(b, lcm(c, d))

ans = dvi_num2(B, C, D) - dvi_num2(A - 1, C, D)

print(ans)

Submission status: Runtime Error

Solution code:
A, B, C, D = [int(_) for _ in input().split()]

import math
def dvi_num(b, c):
    return math.floor(b / c)

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

def dvi_num2(b, c, d):
    return b - dvi_num(b,c) - dvi_num(b,d) + dvi_num(b, lcm(c, d))

ans = dvi_num2(B, C, D) - dvi_num2(A - 1, C, D)
print([dvi_num2(B, C, D), dvi_num2(A - 1, C, D)])

print(ans)

Submission status: Runtime Error

Solution code:
import math

# x 以下でc, d 両方で割れない条件を満たす自然数の個数をf(x, c, d) とすると
# 求める値は f(b, c, d) - f(a-1, c, d)
# x 以下でk で割れる自然数の個数を g(x, k)とすれば
# f(x, c, d) = x - (g(x, c) + g(x, d) - g(x, lcm(c,d)))
# よって計算すべきは
# g(b, c) + g(b, d) - g(b, lcm(c,d)) - ( g(a-1, c) + g(a-1, d) - g(a-1, lcm(c,d)))

def lcm(p, q):
    return p * q // math.gcd(p, q)

def g(x, k):
    return x//k

def f(x, c, d):
    return x - (g(x, c) + g(x, d) - g(x, lcm(c,d)))

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

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

Submission status: Runtime Error

Solution code:
import math

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

# e = lcm(c,d)
e = c*d//math.gcd(c,d)
nc_d = b//e-(a-1)//e
print(b-a+1-nc-nd+nc_d)

Submission status: Runtime Error

Solution code:
import math

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

def div_num(a,x,y):
    return (a//x + a//y - a//lcm(x,y))

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

ans = (b-a+1) - ( div_num(b,c,d) - div_num((a-1),c,d) )

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

def div_num(a,x,y):
    return a//x + a//y - a//lcm(x,y)

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

ans = (b-a+1) - ( div_num(b,c,d) - div_num((a-1),c,d) )

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

def div_num(a,x,y):
    return a//x + a//y - a//lcm(x,y)

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

ans = (b-a+1) - ( div_num(b,c,d) - div_num(a-1,c,d) )

print(ans)

Submission status: Runtime Error

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

C_mod0 = B//C - (A-1)//C
D_mod0 = B//D - (A-1)//D
CD_mod0 = B*math.gcd(C,D)//(C*D) -(A-1)*math.gcd(C,D)//(C*D)
Total = B - A + 1
ans = Total - C_mod0 - D_mod0 + CD_mod0

print(ans)

Submission status: Runtime Error

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

C_mod0 = B//C - (A-1)//C
D_mod0 = B//D - (A-1)//D
CD_mod0 = B*math.gcd(C,D)//(C*D) -(A-1)*math.gcd(C,D)//(C*D)
Total = B - A + 1
ans = Total - C_mod0 - D_mod0 + CD_mod0

print(ans)

Submission status: Runtime Error

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

C_mod0 = B//C - (A-1)//C
D_mod0 = B//D - (A-1)//D
CD_mod0 = B*math.gcd(C,D)//(C*D) -(A-1)*math.gcd(C,D)//(C*D)
Total = B - A + 1
ans = Total - C_mod0 - D_mod0 + CD_mod0
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
u = b - a + 1
import math
div_c = set()
div_d = set()
for i in range(1,int(math.sqrt(c))+):
    if c % i == 0:
        div_c.add(i)
for i in range(1,int(math.sqrt(d))+1):
    if d % i == 0:
        div_d.add(i)
gcd = max(list(div_c & div_d))
cd = c*d/gcd    
n_c = b//c - (a-1)//c
n_d = b//d - (a-1)//d
n_cd = b//(cd) - (a-1)//(cd)
print(int(u - n_c - n_d + n_cd))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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


print(int((b-(a-1)-(cc+dd-s))))

Submission status: Runtime Error

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

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

ac = int((a-1)/c)
ad = int((a-1)/d)
bc = int(b/c)
bd = int(b/d)
acd = int((a-1)/cd)
bcd = int(b/cd)

su = bc + bd - ac - ad - bcd + acd
result = b-(a-1)-su
print(result)

Submission status: Runtime Error

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

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

ac = int((a-1)/c)
ad = int((a-1)/d)
bc = int(b/c)
bd = int(b/d)
acd = int((a-1)/cd)
bcd = int(b/cd)

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

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=list(map(int,input().split()))
a-=1
calc_c=(b-b//c)-(a-a//c)
calc_d=(b-b//d)-(a-a//d)
count=calc_c+calc_d
def lcm(x, y):
    #return (x * y) // math.gcd(x, y)
    return math.floor((x * y) /math.gcd(x, y))


com=lcm(c, d)
tmp=(b-b//com)-(a-a//com)
print(count-tmp)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
dc1=0;dd1=0;dl1=0;dt=0
lcm=(c*d)/math.gcd(c,d)
dc1=int(b/c)-int((a-1)/c)
dd1=int(b/d)-int((a-1)/d)
dl1=int(b/lcm)-int((a-1)/lcm)
dt=dc1+dd1-dl1
print(b-a+1-dt)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
lcm=1;mx=0;dc1=0;dd1=0;dl1=0;dt=0
lcm=(c*d)/math.gcd(c,d)
dc1=int(b/c)-int((a-1)/c)
dd1=int(b/d)-int((a-1)/d)
dl1=int(b/lcm)-int((a-1)/lcm)
dt=dc1+dd1-dl1
print(b-a+1-dt)

Submission status: Runtime Error

Solution code:
def C_AntiDivision():
    from math import gcd
    a,b,c,d = map(int, input().split())
    total = b - a + 1
    total_c = (b // c) + (-a // c) + 1
    total_d = (b // d) + (-a // d) + 1
    gcd_cd = c*d // gcd(c,d)
    total_cd = (b // gcd_cd) + (-a // gcd_cd) + 1
    #print(total_c, total_d, total_cd, gcd_cd)
    print(int(total - total_c - total_d + total_cd))

if __name__ == "__main__":
    C_AntiDivision()

Submission status: Runtime Error

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

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

def F(a, c, d):
    x = a - a//c - a//d + a//lcm(c, d)
    return x

ans = int(F(B, C, D) - F(A-1, C, D))
print(ans)

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)

def F(a, c, d):
    x = a - a//c - a//d + a//lcm(c, d)
    return x

ans = int(F(B, C, D) - F(A-1, C, D))
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
A, B, C, D = map(int, input().split())
if(A % C == 0):
    c_div = (B // C) - (A // C) + 1
else:
    c_div = (B // C) - (A // C + 1) + 1
if(A % D == 0):
    d_div = (B // D) - (A // D) + 1
else:
    d_div = (B // D) - (A // D + 1) + 1
cd_lcm = (C * D) // gcd(C, D)
cd_div = (B // cd_lcm) - (A // cd_lcm + 1) + 1
print((B - A) - (c_div + d_div - cd_div) + 1)

Submission status: Runtime Error

Solution code:
import math

# 01:10
A, B, C, D = tuple([int(a) for a in input().split(' ')])


def func1(n):
    return n - n//C - n//D + n//(C*D//math.gcd(C, D))


print(func1(B) - func1(A-1))

Submission status: Runtime Error

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

A,B,C,D = LI()

'''
cでもdでも割り切れない
逆に割り切れる数を計算する
Bまでで割り切れる個数
Aまでで割り切れる個数
B'-A'でA-Bまでの割り切れる個数が出せる
'''
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

BC = B//C
BD = B//D
BCD = B//lcm(C,D)

#  print('BC, BD, BCD', BC, BD, BCD)
B_count = B - (BC + BD - BCD)

A = A - 1
AC = A//C
AD = A//D
ACD = A//lcm(C,D)
#  print('AC, AD, ACD', AC, AD, ACD)

A_count = A - (AC + AD - ACD)

#  print(B_count, A_count)
print(B_count - A_count)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

lcm = Lcm(C,D)
b = B+B//lcm-B//C-B//D
a = (A-1)+(A-1)//lcm-(A-1)//C-(A-1)//D
print(b-a)

Submission status: Runtime Error

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

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

lcm = lcm(C,D)
b = B+B//lcm-B//C-B//D
a = (A-1)+(A-1)//lcm-(A-1)//C-(A-1)//D
print(b-a)

Submission status: Runtime Error

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

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

lcm = lcm(C,D)
b = B+B//lcm-B//C-B//D
a = (A-1)+(A-1)//lcm-(A-1)//C-(A-1)//D

Submission status: Runtime Error

Solution code:
import math

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


num_b = b - (b // c) - (b // d) + (b // (c * d / math.gcd(c, d)))
num_a = a - 1 - ((a - 1 ) // c) - ((a - 1) // d) + ((a - 1) // (c * d / math.gcd(c, d)))
num = num_b - num_a

print(int(num))

Submission status: Runtime Error

Solution code:
from fractions import gcd

def x(k, c, d):
    rl1 = k
    lcm = c*d / math.gcd(c,d)
    ccount = int(rl1 // c)
    dcount = int(rl1 // d)
    if lcm != 0:
        cdcount = int(rl1 // lcm)
    else:
        cdcount = 0

    return int(rl1 - ccount - dcount + cdcount)

a, b, C, D = map(int, input().split())
print(x(b, C, D) - x(a-1, C, D))

Submission status: Runtime Error

Solution code:
import math

a, b, C, D = map(int, input().split())

def x(k, c, d):
    rl1 = k
    lcm = c*d / math.gcd(c,d)
    ccount = int(rl1 // c)
    dcount = int(rl1 // d)
    if lcm != 0:
        cdcount = int(rl1 // lcm)
    else:
        cdcount = 0

    return int(rl1 - ccount - dcount + cdcount)

print(x(b, C, D) - x(a-1, C, D))

Submission status: Runtime Error

Solution code:
import math

def x(k, c, d):
    rl1 = k
    lcm = c*d / math.gcd(c,d)
    ccount = int(rl1 // c)
    dcount = int(rl1 // d)
    if lcm != 0:
        cdcount = int(rl1 // lcm)
    else:
        cdcount = 0

    return int(rl1 - ccount - dcount + cdcount)

a, b, C, D = map(int, input().split())
print(x(b, C, D) - x(a-1, C, D))

Submission status: Runtime Error

Solution code:
import math

def x(k, c, d):
    rl1 = k
    lcm = c*d / math.gcd(c,d)
    ccount = int(rl1 // c)
    dcount = int(rl1 // d)
    if lcm != 0:
        cdcount = int(rl1 // lcm)
    else:
        cdcount = 0
        

    return int(rl1 - ccount - dcount + cdcount)

a, b, C, D = map(int, input().split())

print(x(b, C, D) - x(a-1, C, D))

Submission status: Runtime Error

Solution code:
import math

def x(k, c, d):
    rl1 = k
    lcm = c*d / math.gcd(c,d)
    ccount = int(rl1 // c)
    dcount = int(rl1 // d)
    cdcount = int(rl1 // lcm)

    return int(rl1 - ccount - dcount + cdcount)

a, b, C, D = map(int, input().split())

print(x(b, C, D) - x(a-1, C, D))

Submission status: Runtime Error

Solution code:
from math import gcd

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


def cnt_div(a, b, x):
    q, r = divmod(a, x)

    if r == 0:
        m = q - 1
    else:
        m = q

    n = b // x

    return n - m


num_c = cnt_div(a, b, c)
num_d = cnt_div(a, b, d)
lcm = int((c * d) / gcd(c, d))
num_c_d_gcd = cnt_div(a, b, lcm)

print((b - a + 1) - (num_c + num_d - num_c_d_gcd))

Submission status: Runtime Error

Solution code:
import math

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n + 1)
    n_count = n_upper - n_lower + 1
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = int((C / math.gcd(C, D)) * D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import math

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n + 1)
    n_count = n_upper - n_lower + 1
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C / math.gcd(C, D)) * D
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

U = B - A + 1

def number(R):
        return ((B // R) - ((A - 1) // R))

possible_C = number(C)
possible_D = number(D)
possible_CD = number((C * D) // math.gcd(C, D))

print(U)
print(possible_C)
print(possible_D)
print(possible_CD)

print(U - (possible_C + possible_D) + possible_CD)

Submission status: Runtime Error

Solution code:
#ABC131c

import math
from functools import reduce

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


count_c=b//c - (a-1)//c
count_d=b//d - (a-1)//d
count_cd=b//(c*d//math.gcd(c,d)) - (a-1)//(c*d//math.gcd(c,d))

print(b-a+1-count_c-count_d+count_cd)

Submission status: Runtime Error

Solution code:
#ABC131c

import math


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


count_c=b//c - (a-1)//c
count_d=b//d - (a-1)//d
count_cd=b//(c*d//math.gcd(c,d)) - (a-1)//(c*d//math.gcd(c,d))

print(b-a+1-count_c-count_d+count_cd)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d= list(map(int, input().split()))
m=0
x, y, z=[0,0,0]
def lcm(a, b):
	return int(a*b/math.gcd(a,b))
for i in range(a,b+1):
	if i%c==0:
		x=1+math.floor((b-i)/c)
		break
for i in range(a,b+1):
	if i%d==0:
		y=1+math.floor((b-i)/d)
		break
for i in range(a,b+1):
	if i%lcm(c,d)==0:
		z=1+math.floor((b-i)/lcm(c,d))
		break
print(b-a+1-x-y+z)
# print(x, y, z)
# print(lcm(c, d))
# print(math.gcd(c,d))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d= list(map(int, input().split()))
m=0
for i in range(a,b+1):
	if i%c==0:
		x=1+math.floor((b-i)/c)
		break
for i in range(a,b+1):
	if i%d==0:
		y=1+math.floor((b-i)/d)
		break
for i in range(a,b+1):
	if i%(c*d)==0:
		z=1+math.floor((b-i)/(c*d))
		break
print(b-a+1-x-y+z)
# print(x, y, z)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d= list(map(int, input().split()))
m=0
for i in range(a,b+1):
	if i%c==0:
		x=1+math.floor((b-i)/c)
		break
for i in range(a,b+1):
	if i%d==0:
		y=1+math.floor((b-i)/d)
		break
for i in range(a,b+1):
	if i%(c*d)==0:
		z=1+math.floor((b-i)/(c*d))
		break
print(b-a+1-x-y+z)
print(x, y, z)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
A,B,C,D=map(int, input().split())
CD=int(np.lcm(C,D))
maxC=int(B/C)*C
maxD=int(B/D)*D
maxCD=int(B/CD)*CD
minC=(int(A/C)+1)*C
minD=(int(A/D)+1)*D
minCD=(int(A/CD)+1)*CD
Ccount=int((maxC-minC)/C)+1
Dcount=int((maxD-minD)/D)+1
CDcount=int((maxCD-minCD)/CD)+1
print(B-A+1-Ccount-Dcount+CDcount)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D=map(int, input().split())
CD=int((C*D)/math.gcd(C,D))
maxC=int(B/C)*C
maxD=int(B/D)*D
maxCD=int(B/CD)*CD
minC=(int(A/C)+1)*C
minD=(int(A/D)+1)*D
minCD=(int(A/CD)+1)*CD
Ccount=int((maxC-minC)/C)+1
Dcount=int((maxD-minD)/D)+1
CDcount=int((maxCD-minCD)/CD)+1
print(B-A+1-Ccount-Dcount+CDcount)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int, input().split())
import math
n1=math.ceil(a/min(c,d))
if a<=min((c,d))*n1<=b:
    l1=(b-min((c,d))*n1)//min((c,d))+1
else: l1=0
  n2=math.ceil(a/max(c,d))
if a<=max((c,d))*n2<=b:
    l2=(b-max((c,d))*n2)//max((c,d))+1
else: l2=0
lcm=(c*d)//math.gcd(c, d)
n3=math.ceil(a/lcm)
if a<=lcm<=b:
    l3=(b-lcm)*n3//lcm+1
else: l3=0
ans=(b-a+1)-(l1+l2-l3)
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())
lcm = lcm(C,D)
print((B - A + 1) - ((B // D - (A - 1) // D) + (B // C - (A - 1) // C) - (B // lcm - (A - 1) // lcm)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
now_time = 0
global tf
tf = False

def finish_work(now_time, works):
    global tf
    if len(works) == 0 or tf == True:
        tf = True
        return True
    sums = sum([i[0] for i in works]) 
    maxs = max ([i[1] for i in works])
    if maxs < sums:
        return 0
    for index, i in enumerate(works):
        if now_time + i[0] <= i[1]:
            work_list = works.copy()
            work_list.pop(index)
            finish_work(now_time + i[0], work_list)

works = []

for i in range(n):
    a = list(map(int, input().split()))
    works.append(a)

for index, i in enumerate(works):
    
    if now_time + i[0] <= i[1]:
        work_list = works.copy()
        work_list.pop(index)
        finish_work(now_time + i[0], work_list)

if tf:
    print("Yes")
else:
    print("No")

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = list(map(int,input().split()))
cka = int(math.floor(b/float(c)) - math.ceil(a/float(c)) + 1.0)
dka = int(math.floor(b/float(d)) - math.ceil(a/float(d)) + 1.0)
lc = int((c*d)/float(math.gcd(c, d)))
dcka = int(math.floor(b/float(lc)) - math.ceil(a/float(lc)) + 1.0)
print(b-a+1-cka-dka+dcka)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = list(map(int,input().split()))
cka = int(math.floor(b/float(c)) - math.ceil(a/float(c)) + 1.0)
dka = int(math.floor(b/float(d)) - math.ceil(a/float(d)) + 1.0)
lc = (c*d)//(math.gcd(c, d))
dcka = int(math.floor(b/float(lc)) - math.ceil(a/float(lc)) + 1.0)
print(b-a+1-cka-dka+dcka)

Submission status: Runtime Error

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

count = 0
len = B-A+1

count += math.floor(B/C)
count -= math.floor((A-1)/C)
count += math.floor(B/D)
count -= math.floor((A-1)/D)

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

print(len - count)

Submission status: Runtime Error

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

bk =  B - B//C - B//D + B//kobaisu

ak = (A-1) - (A-1)//C - (A-1)//D + (A-1)//kobaisu

print(bk-ak)

Submission status: Runtime Error

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

A,B,C,D = map(int,input().split())
bk = B - B//C - B//D + B//gcm(C,D)
ak = (A-1) - (A-1)//C - (A-1)//D + (A-1)//gcm(C,D)

print(bk-ak)

Submission status: Runtime Error

Solution code:
import math

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

def func(n, p, q):
    return n - (n//p + n//q - n//lcm(p, q))

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

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

Submission status: Runtime Error

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

A = A-1
c_and_d=C*D
#CとDの最小公倍数を求める
lcm = int(C*D/math.gcd(C,D))
# print('最小公倍数:',lcm)

count_C =0
count_D =0
count_C_and_D =0

count_C = int(B/C)-int(A/C)
count_D = int(B/D)-int(A/D)
count_C_and_D = int(B/lcm)-int(A/lcm)
A = A+1
print((B-A+1) -(count_C + count_D - count_C_and_D))

Submission status: Runtime Error

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

A = A-1
c_and_d=C*D
#CとDの最小公倍数を求める
lcm = int(C*D/math.gcd(C,D))
# print('最小公倍数:',lcm)

count_C =0
count_D =0
count_C_and_D =0

count_C = int(B/C)-int(A/C)
count_D = int(B/D)-int(A/D)
count_C_and_D = int(B/lcm)-int(A/lcm)
A = A+1
# print(A,B,count_C , count_D , count_C_and_D)
print((B-A+1) -(count_C + count_D - count_C_and_D))

Submission status: Runtime Error

Solution code:
import math

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

a2 = a - 1

num1 = int(b / d) + int(b / c) - int(b / (c * d / math.gcd(c, d)))
num2 = int(a2 / d) + int(a2 / c) - int(a2 / (c * d / math.gcd(c, d)))

ans = (b - a2) - (num1 - num2)

print(ans)

Submission status: Runtime Error

Solution code:
#整数 A,B,C,D が与えられます。A 以上 B 以下の整数のうち、C でも D でも割り切れないものの個数を求めてください。
#B 以下の整数の個数 (B 個) から、B 以下の C の倍数の個数と B 以下の D の倍数の個数を引き、
#重複して引いたものを足し戻す

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

#B以下のCの倍数の数
if A%C==0 or B%C==0:
    c = B//C - A//C + 1
else:
    c = B//C - A//C
#B以下のDの倍数の数
if A%D==0 or B%C==0:
    d = B//D - A//D + 1
else:
    d = B//D - A//D 
#重複分（最小公倍数）
x = C*D//math.gcd(C,D)
if A%x == 0 or B%x == 0:
    cd = B//x - A//x +1
else:
    cd = B//x - A//x

print(B - A + 1 - c - d + cd)

Submission status: Runtime Error

Solution code:
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
%matplotlib inline
#整数 A,B,C,D が与えられます。A 以上 B 以下の整数のうち、C でも D でも割り切れないものの個数を求めてください。
#B 以下の整数の個数 (B 個) から、B 以下の C の倍数の個数と B 以下の D の倍数の個数を引き、
#重複して引いたものを足し戻す

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

#B以下のCの倍数の数
if A%C==0 or B%C==0:
    c = B//C - A//C + 1
else:
    c = B//C - A//C
#B以下のDの倍数の数
if A%D==0 or B%C==0:
    d = B//D - A//D + 1
else:
    d = B//D - A//D 
#重複分（最小公倍数）
x = C*D//math.gcd(C,D)
if A%x == 0 or B%x == 0:
    cd = B//x - A//x +1
else:
    cd = B//x - A//x

print(B - A + 1 - c - d + cd)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math

def lcm(x, y):
    return (x * y) // math.gcd(x, y)
    
a, b, c, d = map(int,input().split())
def cal(i, j, k):
    return i // j + i // k - i // lcm(j, k)

if a % c == 0 or a % d == 0:
    print(b - a - (cal(b, c, d) - cal(a, c, d)))
else:
    print(b - a - (cal(b, c, d) - cal(a, c, d)) + 1)

Submission status: Runtime Error

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

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

answer_C = B // C - (A-1) // C
answer_D = B // D - (A-1) // D
answer_lcm = B // lcm_number - (A-1) // lcm_number

print(all_number - answer_C - answer_D + answer_lcm)

Submission status: Runtime Error

Solution code:
A,B,C,D = map(int, input().split())
lcm_number = C*D // math.gcd(C, D)  #最小公倍数
all_number = B -A + 1

answer_C = B // C - (A-1) // C
answer_D = B // D - (A-1) // D
answer_lcm = B // lcm_number - (A-1) // lcm_number

print(all_number - answer_C - answer_D + answer_lcm)