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())
nbc = b // c
nac = (a - 1) // c
nc = nbc - nac
nbd = b // d
nad = (a - 1) // d
nd = nbd - nad
cd = (c * d) // math.gcd(c, d)
nbcd = b // cd
nacd = a // cd
ncd = nbcd - nacd
t = b - a + 1 - nc - nd + ncd
print(t)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import fractions

def lcm(k):
    ans = k[0]
    for i in range(1, len(k)):
        ans = ans * k[i] // fractions.gcd(ans, k[i])
    return ans

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

cbaisu = baisu2(a, b, c)
dbaisu = baisu2(a, b, d)
cdbaisu = baisu2(a, b, lcm([c, d]))

print(b-a+1-cbaisu-dbaisu+cdbaisu)

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)
e = lcm(c,d)

f = (b//c + b//d) - b//e
g = ((a-1)//c + (a-1)//d) - (a-1)//e
print (b-a+1-(f-g))

Submission status: Runtime Error

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

lcm = c*d/gcd(c,d)
print(b - a + 1 - int(b/c) + int((a-1)/c) - int(b/d) + int((a-1)/d) + int(b/lcm) - int((a-1)/lcm))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

cntC = B // C - A // C + int(A % C == 0)
cntD = B // D - A // D + int(A % D == 0)

lcm = C * D // math.gcd(C, D)
cntCD = B // lcm - A // lcm + int(A % lcm == 0)

print((B - A + 1) - (cntC + cntD - cntCD))

Submission status: Runtime Error

Solution code:
import math

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

def divide(n):
    return (b // n) - ((a-1) // n)

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

ans = b - a + 1

ans -= divide(c)

ans -= divide(d)

ans += divide(lcm(c,d))

print(ans)

Submission status: Runtime Error

Solution code:
import math
def count(n, m, l):
    c_m = n // m
    c_l = n // l
    c_ml = n // (m * l // math.gcd(m, l))
    return n - (c_m + c_l - c_ml)

a, b, c, d = map(int, input().split())
b_tar = count(b, c, d)
a_tar = count(a, c, d)
is_plus_a = not(bool(a % c == 0 or a % d == 0))
ans = b_tar - a_tar
if is_plus_a: ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
def count(n, m, l):
    c_m = n // m
    c_l = n // l
    c_ml = n // (m * l // math.gcd(m, l))
     return n - (c_m + c_l - c_ml)

a, b, c, d = map(int, input().split())
b_tar = count(b, c, d)
a_tar = count(a, c, d)
is_plus_a = not(a % c == 0 or a % d == 0)
ans = b_tar - a_tar
if is_plus_a: ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math
def count(n, m, l):
    c_m = n // m
    c_l = n // l
    c_ml = n // (m * l // math.gcd(m, l))
    return n - (c_m + c_l - c_ml)

a, b, c, d = map(int, input().split())
b_tar = count(b, c, d)
a_tar = count(a, c, d)
is_plus_a = not(a % c == 0 or a % d == 0)
ans = b_tar - a_tar
if is_plus_a: ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
# 判定機にmathがインストールされていないため、
# gcd=最小公倍数、lcm=最少公約数(返り値整数)を実装
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    z = None
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        return z


def lcm(m, n):
    return (m * n) // gcd(m, n)


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

# check
AB = len(list(range(A, B + 1)))

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // C

lcm_CD = lcm(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

print(AB - C_cnt - D_cnt + lcm_cnt)

Submission status: Runtime Error

Solution code:
from math import gcd

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

# check
AB = len(list(range(A, B + 1)))

C_cnt = B // C - (A - 1) // C
D_cnt = B // D - (A - 1) // C

lcm_CD = C * D // gcd(C, D)
lcm_cnt = B // lcm_CD - (A - 1) // lcm_CD

print(AB - C_cnt - D_cnt + lcm_cnt)

Submission status: Runtime Error

Solution code:
# input
A, B, C, D = int(input())

# check
ans = len([1 for i in range(A, B + 1) if i % C != 0 and i % D != 0])

print(ans)

Submission status: Runtime Error

Solution code:
import math
li = list(map(int,input().split()))
countC = li[1] // li[2] - (li[0]-1) // li[2]

countD = li[1] // li[3] - (li[0]-1) // li[3]

lcm = (li[2] * li[3]) // math.gcd(li[2], li[3])

countCD = li[1] // lcm - (li[0]-1) // lcm

re = (li[1] - li[0] + 1) - (countC +countD - countCD)

print(re)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
a, b, c, d  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

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

nlcmc = b // c
nlcmd = b // d
nlcmcd = b // lcm(c, d)
nb = b - (nlcmc + nlcmd - nlcmcd)

a -= 1
nlcmc = a // c
nlcmd = a // d
nlcmcd = a // lcm(c, d)
na = a - (nlcmc + nlcmd - nlcmcd)

print(nb - na)

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 sj(base, i1, i2):
    cz = base // i1
    dz = base // i2
    cd = base // lcm(i1, i2)
    return base - (cz + dz - cd)


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

Submission status: Runtime Error

Solution code:
def list_lcm(A):
    """N個の最小公倍数
    Args:
        A (list[int])

    Returns:
        int: 最小公倍数

    Examples:
        >>> list_lcm([12, 34, 54, 65])
        119340
    """
    ans = A[0]
    for i in range(1, len(A)):
        ans = ans * A[i] // gcd(ans, A[i])
    return ans


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

    lcm_C_D = list_lcm([C, D])
    ans_B = B - B // C - B // D + B // lcm_C_D
    ans_A = A - A // C - A // D + A // lcm_C_D

    print(ans_B - ans_A)


resolve()

Submission status: Runtime Error

Solution code:
import math
def lcm(n,m): return n*m//math.gcd(n,m)
A,B,C,D=map(int,input().split())
print(((B-A)-(((B-A)//C)+((B-A)//D)))+((B-A)//lcm(C,D)))

Submission status: Runtime Error

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))


a,b,c,d=input_list()

l_c=math.ceil(a/c)
h_c=b//c
c_num=h_c-l_c+1

l_d=math.ceil(a/d)
h_d=b//d
d_num=h_d-l_d+1


g=c*d//math.gcd(c,d)
l_g=math.ceil(a/g)
h_g=b//g
g_num=h_g-l_g+1

ans=b-a+1-c_num-d_num+g_num
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions from gcd

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)
lcm = lambda x, y: x * y / gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= A // C
    cnt -= A // D

    cnt -= B // lcm(C, D)
    cnt += A // lcm(C, D)
    print(E - int(cnt))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
import fractions import gcd

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)
lcm = lambda x, y: x * y / gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= A // C
    cnt -= A // D

    cnt -= B // lcm(C, D)
    cnt += A // lcm(C, D)
    print(E - int(cnt))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue
from functools import gcd

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

# lcm = lambda x, y: x * y / math.gcd(x, y)
lcm = lambda x, y: x * y / gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= A // C
    cnt -= A // D

    cnt -= B // lcm(C, D)
    cnt += A // lcm(C, D)
    print(E - int(cnt))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
import heapq
import re
import queue

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    E = B - A + 1
    cnt = 0

    cnt += B // C
    cnt += B // D
    cnt -= A // C
    cnt -= A // D

    cnt -= B // lcm(C, D)
    cnt += A // lcm(C, D)
    print(E - int(cnt))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
cwari=b//c-(a-1)//c
dwari=b//d-(a-1)//d
import math
cd=math.gcd(c,d)
cdwari=b//cd-(a-1)//cd
print(cwari)

ans=(b-a)+1-cwari-dwari+cdwari
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
import fractions
s1 = b//c
s2 = (a-1)//c
p1 = b//d
p2 = (a-1)//d
e = c*d//math.gcd(c,d)
q1 = b//e
q2 = (a-1)//e
print(b-a+1-(s1+p1-s2-p2-q1+q2))

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
import math
s1 = b//c
s2 = (a-1)//c
p1 = b//d
p2 = (a-1)//d
e = c*d//math.gcd(c,d)
q1 = b//e
q2 = (a-1)//e
print(b-a+1-(s1+p1-s2-p2-q1+q2))

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = list(map(int, input().split()))
ans = []
for n in [a - 1, b]:
    mc = n // c
    md = n // d
    cd = c * d // math.gcd(c, d)
    mcd = n // cd
    ans.append(n - mc - md + mcd)
print(int(ans[1] - ans[0]))

Submission status: Runtime Error

Solution code:
import math


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


def count(X, C, D):
    ret = X - (X//C + X//D - X//lcm(C, D))
    return ret


def main():
    A, B, C, D = map(int, input().split())
    ans = count(B, C, D) - count(A-1, C, D)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from fractions import gcd
A,B,C,D = map(int,input())
N=B-A+1
print(N-(N//C)-(N//D)+(N//(gcd(C,D))))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:52:33 2020

@author: Kanaru Sato
"""

import fraction

def divnum(x,y,n):
    if x%n == 0:
        return y//n - x//n + 1
    else:
        return y//n - x//n

a,b,c,d = list(map(int,input().split()))
cd = (c*d)/fraction.gcd(c,d)
ans = divnum(a,b,c) + divnum(a,b,d) - divnum(a,b,cd)
print(int(b-a+1-ans))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri May 15 00:52:33 2020

@author: Kanaru Sato
"""

import math

def divnum(x,y,n):
    if x%n == 0:
        return y//n - x//n + 1
    else:
        return y//n - x//n

a,b,c,d = list(map(int,input().split()))
cd = (c*d)/math.gcd(c,d)
ans = divnum(a,b,c) + divnum(a,b,d) - divnum(a,b,cd)
print(int(b-a+1-ans))

Submission status: Runtime Error

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

"""
両方に関して割り切れるものの個数から公倍数で割り切れるものを除けばいい
"""
import math

C = b//c - (a-1)//c
D = b//d - (a-1)//d

# 最小公倍数を求める
CD = math.gcd(c, d)
lcm = (c * d) // CD

G = b//lcm - (a-1)//lcm


count = C + D - G
print(b - a + 1 - count)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
if c <=0 or d <= 0:
    print("No")
ans = c * d // math.gcd(c,d)
i = a
j = a
while True:
    if i % c == 0:
        break
    i += 1
while True:
    if j % d == 0:
        break
    j += 1
k = min(i,j)
while True:
    if k % ans == 0:
        break
    k += 1
ii = (b-i)//c 
jj = (b-j)//d 
kk = (b-k)//ans 
print(b-a-ii-jj+kk)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
ans = c * d // math.gcd(c,d)
i = a
j = a
while True:
    if i % c == 0:
        break
    i += 1
while True:
    if j % d == 0:
        break
    j += 1
k = min(i,j)
while True:
    if k % ans == 0:
        break
    k += 1
ii = (b-i)//c 
jj = (b-j)//d 
kk = (b-k)//ans 
print(b-a-ii-jj+kk)

Submission status: Runtime Error

Solution code:
l=[]
for i in range(1,n+1):
  l.append(abs(l-1+i))
mi=l.index(min(l))
print(n*(l-1)+sum(range(1,n+1))-l-mi)

Submission status: Runtime Error

Solution code:
from math import ceil, floor,gcd

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

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


Cdiff = floor(B/C) - floor((A-1)/C)
Ddiff = floor(B/D) - floor((A-1)/D)

CD = lcm(C,D)
CDdiff = floor(B/CD) - floor((A-1)/CD)



res = Cdiff+Ddiff-CDdiff
print((B-A+1)-res)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math

# 標準入力の取得
A, B, C, D = list(map(int, input().split()))


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


# 求解処理
div_C = (B // C) - ((A - 1) // C)
div_D = (B // D) - ((A - 1) // D)
lcm_CD = lcm(C, D)
div_lcm_CD = (B // lcm_CD) - ((A - 1) // lcm_CD)
result = (B - A + 1) - div_C - div_D + div_lcm_CD

# 結果出力
print(result)

Submission status: Runtime Error

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
from operator import itemgetter
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, b, c, d = map(int, input().split())


def func(n, c, d):
    x = n//c
    y = n//d
    z = n//((c * d) // math.gcd(c, d))
    zz = (x+y)-z
    return zz


tmp = b-func(b, c, d)
tmp2 = (a-1)-func(a-1, c, d)
print(tmp-tmp2)
#print('test', func(6, 2, 3))

Submission status: Runtime Error

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

print(b - b//c - b//d + b//((c*d)//math.gcd(c, d)) - (a-1 - (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 = map(int,input().split())
e,f,g,h,i,j = b // c,b // d,(a-1) // c,(a-1) // d,b // ((c*d)/math.gcd(c,d)),(a-1) // ((c*d)/math.gcd(c,d))
print(int(b-(e+f-i)-(a-1-(g+h-j))))

Submission status: Runtime Error

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

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())
L = lcm(C,D)
#A-1以下のCorDで割り切れる個数
a = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)
#B以下のCorDで割り切れる個数
b = B//C + B//D - B//lcm(C,D)
ans = B-(A-1) - (b-a)
print(ans)

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)
s = lcm(C,D)
X =  A - (A//C + A //D - A//s)
Y =  B - (B//C + B //D - B//s)
print(Y-X)

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

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)

LCM = lcm(C,D)
BC = B // C
BD = B // D
BCD = B // LCM
AC = (A-1) // C
AD = (A-1) // D
ACD = (A-1) // LCM
x = B - BC - BD + BCD
y = (A-1) - AC - AD + ACD
print(x - y)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math


def main():
    A, B, C, D = [int(x) for x in input().split()]
    N = B - A + 1
    g = math.gcd(C, D)
    l = (C * D) / g
    b = anti(B, C, D, l)
    a = anti((A-1), C, D, l)
    print(N - (b - a))


def anti(x, y, z, l):
    return int(x / y) + int(x / z) - int(x / l)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

num_b_c = b//c
num_b_d = b//d
num_b_cd = b//lcm

if a%c==0:
    num_a_c = a//c - 1
else:
    num_a_c = a//c

if a%d==0:
    num_a_d = a//d - 1
else:
    num_a_d = a//d

if a%lcm==0:
    num_a_cd = a//lcm - 1 
else:

    num_a_cd = a//lcm


alls = b - a + 1


c_div = num_b_c - num_a_c
d_div = num_b_d - num_a_d

cd_div = num_b_cd -num_a_cd


print(alls - ( c_div + d_div - cd_div))

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)

LCM=lcm(C,D)

Cwari=(B//C)-((A-1)//C)
Dwari=(B//D)-((A-1)//D)
CDwari=(B//LCM)-(A//LCM)

print((B-A+1)-(Cwari+Dwari-CDwari))

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a, b, c, d = Is()
def calc(num, x, y):
    l = (x*y)/gcd(x, y)
    return num - floor(num/x) - floor(num/y) + floor(num/l)

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


a, b, c, d = Is()
def calc(num, x, y):
    l = x*y/gcd(x, y)
    return num - floor(num/x) - floor(num/y) + floor(num/l)

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

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
a -= 1
from math import gcd
divac = a // c
divad = a // d
divbc = b // c
divbd = b // d
divacd = a // (c*d//gcd(c,d))
divbcd = b // (c*d//gcd(c,d))
Acd = divac + divad - divacd
Bcd = divbc + divbd - divbcd
wareru = Bcd - Acd
ans = b-a-wareru
print(ans)

Submission status: Runtime Error

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

div_c = b//c - a//c
div_d = b//d - a//d
lcm_cd = c*d//math.gcd(c, d)
div_cd = b//lcm_cd - a//lcm_cd

print(b - a + 1 - div_c - div_d + div_cd)

Submission status: Runtime Error

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

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

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

ans_c = (B - A) // C
ans_d = (B - A) // D
i = (B - A) // (C * D // gcd(C, D))

print(B - A - ans_c - ans_d + i)

Submission status: Runtime Error

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

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

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

print(a*b // gcd(a, b))

ans_c = (B - A) // C
ans_d = (B - A) // D
i = (B - A) // (C * D // gcd(C, D))

print(B - A - ans_c - ans_d + i)

Submission status: Runtime Error

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

ans_c = (B - A) // C
ans_d = (B - A) // D
i = (B - A) // (C * D // math.gcd(C, D))

print(B - A - ans_c - ans_d + i)

Submission status: Runtime Error

Solution code:
import numpy as np
A, B, C, D = map(int, input().split())
s = np.arange(A, B+1)

s = s[np.where(s%C != 0)]
s = s[np.where(s%D != 0)]

print(s.shape[0])

Submission status: Runtime Error

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

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

c = B // C - (A - 1) // C 
d = B // D - (A - 1) // D 
e = B // E - (A - 1) // E
ans = B - A - c - d + e + 1
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 solve(n):
    return n - n//C - n//D + n//lcm(C, D)
print(solve(B) - solve(A-1))

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 solve(n):
    ans = n - n//C - n//D + n//lcm(C, D)
    return ans
answer = solve(B) - solve(A-1)
print(answer)

Submission status: Runtime Error

Solution code:
# ABC131C

def euclid(m, n):
    m0 = m = abs(m)
    n0 = n = abs(n)
    while n != 0:
        m, n = n, m % n
    qm = m0 // m
    lcm = qm * n0
    return lcm


def check(a, b, c):
    x = a // c
    y = b // c
    if x * c < a:
        x += 1
    return y - x + 1

a, b, c, d = map(int, input().split())
nc = check(a, b, c)
nd = check(a, b, d)
ncd = check(a, b, lcm(c, d))
print(b - a + 1 -(nc + nd - ncd))

Submission status: Runtime Error

Solution code:
# ABC131C

def euclid(m, n):
    m0 = m = abs(m)
    n0 = n = abs(n)
    while n != 0:
        m, n = n, m % n
    qm = m0 // m
    lcm = qm * n0
    return lcm


def check(a, b, c):
    x = a // c
    y = b // c
    if x * c < a:
        x += 1
    return y - x + 1

a, b, c, d = map(int, input().split())
nc = check(a, b, c)
nd = check(a, b, d)
ncd = check(a, b, sp.lcm(c, d))
print(b - a + 1 -(nc + nd - ncd))

Submission status: Runtime Error

Solution code:
# ABC131C

def check(a, b, c):
    x = a // c
    y = b // c
    if x * c < a:
        x += 1
    return y - x + 1

a, b, c, d = map(int, input().split())
nc = check(a, b, c)
nd = check(a, b, d)
ncd = check(a, b, sp.lcm(c, d))
print(b - a + 1 -(nc + nd - ncd))

Submission status: Runtime Error

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


t = math.gcd(C, D)

m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)

print(B-A+1-m+n)

Submission status: Runtime Error

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

m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)

print(B-A+1-m+n)

Submission status: Runtime Error

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

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

m = math.floor(B / C) + math.floor(B / D) - math.floor(B / t)
 
n = math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / t)

print(B-A+1-m+n)

Submission status: Runtime Error

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

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

m = B - (math.floor(B / C) + math.floor(B / D) - math.floor(B / (t)))
 
n = A - 1 - (math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / (t)))

print(m-n)

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)

t = lcm(C, D)

m = B - (math.floor(B / C) + math.floor(B / D) - math.floor(B / (t)))
 
n = A - 1 - (math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / (t)))

print(m-n)

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)

t = lcm(C, D)


# C = 2
# D = 2

m = B - (math.floor(B / C) + math.floor(B / D) - math.floor(B / (t)))
 
n = A-1 - (math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / (t)))

print(m-n)

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)

t = lcm(C, D)

m = B - (math.floor(B / C) + math.floor(B / D) - math.floor(B / (t)))
 
n = A-1 - (math.floor((A-1) / C) + math.floor((A-1) / D ) - math.floor((A-1) / (t)))

print(m-n)

Submission status: Runtime Error

Solution code:
# C - Anti-Division

from math import gcd

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

CxD = C * D // gcd(C, D)

total_C = B // C
total_D = B // D
total_CxD = B // CxD

sub_C = (A - 1) // C
sub_D = (A - 1) // D
sub_CxD = (A - 1) // CxD

print((B - (A - 1)) -
        (total_C + total_D - total_CxD) + (sub_C + sub_D - sub_CxD))

Submission status: Runtime Error

Solution code:
import sys
#from collections import defaultdict, deque, Counter
#from bisect import bisect_left
#import heapq
import math
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

#n = int(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
a,b,c,d = map(int, stdin.readline().rstrip().split())
#S = [list(stdin.buffer.readline().decode().rstrip()) for _ in range(h)]

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

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

# b以下
cwari = b//c
dwari = b//d
cdwari = b//cd
ub = b-cwari-dwari+cdwari

# a以下
cwari = a//c
dwari = a//d
cdwari = a//cd
ua = a-cwari-dwari+cdwari

if a%c != 0 and a%d !=0:
    print(ub-ua+1)
else:
    print(ub-ua)

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(' '))
res = 0
can_dived_c = B // C - (A - 1) // C
can_dived_d = B // D - (A - 1) // D
can_dived_both = B // lcm(C, D) - (A - 1) // lcm(C, D)
res = B - (A - 1) - can_dived_c - can_dived_d + can_dived_both
print(res)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
lcm_cd = (c * d) // math.gcd(c, d)
total = b - a + 1
d_c = b // c - (a - 1) // c
d_d = b // d - (a - 1) // d
d_cd = b // lcm_cd - (a - 1) // lcm_cd
print(int(total - (d_c + d_d - d_cd)))