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: Wrong Answer

Solution code:
# coding: utf-8
import sys
# import bisect
# import math
# import numpy as np
# from fractions import gcd

"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

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

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    a, b, c, d = ip.IL()
    memo = b - a + 1
    memo2 = id.lcm(c, d)
    a_c = (a-1) // c
    a_d = (a-1) // d
    b_c = b // c
    b_d = b // d
    b_cd = b // memo2
    a_cd = (a-1) // memo2

    acd = a_c + a_d
    bcd = b_c + b_d
    kaburi = b_cd - a_cd
    print(memo)
    print(a_c, a_d, b_c, b_d, b_cd, a_cd)
    print(bcd - acd - kaburi)
    ans = bcd - acd - kaburi
    print(memo - ans)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

n = math.ceil(A / C)
m = math.floor(B / C)
if m >= n:
  count_div += m - n + 1

l = math.ceil(A / D)
k = math.floor(B / D)
if k >= l:
  count_div += k - l + 1

j = math.ceil(A / (C * D))
i = math.floor(B / (C * D))
if i >= j:
  count_div -= i - j + 1

print(B - A + 1 - count_div)

Submission status: Wrong Answer

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

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

first = ((B - A) // C) + 1
second = ((B - A) // D) + 1
third = ((B - A) // LCM) + 1

total = first + second - third

print(int(B - A - total + 1))

Submission status: Wrong Answer

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

for n in range(B-A+1):
  if (A + n) %C !=0 and (A+n)% D != 0:
    counter += 1

print(counter)
"""
CSeries = B//C -(A-1)//C
DSeries = B //D - (A-1) //D
CDSeries = B//(C*D) - (A-1)//(C*D)

Answer2 = B-A +1 - CSeries - DSeries + CDSeries

print(Answer2)

Submission status: Wrong Answer

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

def lcm(a, b):
    return a * b / gcd(a, b)
A, B, C, D = map(int, input().split())
diff = B - A
ret = 0
if C == 1 or D == 1:
    print(0)
else:
    ret += diff // C
    if A % C == 0:
        ret += 1
    ret += diff // D
    if A % D == 0:
        ret += 1
    a = diff // int(lcm(C, D))
    print(diff-ret+a)

Submission status: Wrong Answer

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

ans = 0

c_n_min = math.ceil(A / C)
c_n_max = math.floor(B / C)
c_n = c_n_max - c_n_min + 1

d_n_min = math.ceil(A / D)
d_n_max = math.floor(B / D)
d_n = d_n_max - d_n_min + 1

cd = C * D / fractions.gcd(C,D)
cd_n_min = math.ceil(A / cd)
cd_n_max = math.floor(B / cd)
cd_n = cd_n_max - cd_n_min + 1

ans = (B - A + 1) - (c_n + d_n - cd_n)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

a, b, c, d = [int(i) for i in input().split()]
#
#num = np.arange(b - a + 1) + a
#
#if b < c and b < d:
#    print('0')
#    exit(0)
#
#m = min(c, d)
#div = max(c, d)
#tmp = []
#div = num[0] // div + div
#index = 0
#while True:
#    if n[index] % div != 0:
#        if index + div >
#        tmp += range(n[index], n[index])
#        index += 1
#    else:
#        index += div
#
#tmp = np.array(tmp)
#print(tmp[tmp % m == 0].shape[0])


size = b - a + 1
c_num_a = a // c
d_num_a = a // d
cd_num_a = a // (c * d)
c_num_b = b // c
d_num_b = b // d
cd_num_b = b // (c * d)

c_num = c_num_b - c_num_a
d_num = d_num_b - d_num_a
cd_num = cd_num_b - cd_num_a

if a % c == 0:
    c_num += 1
if a % d == 0:
    d_num += 1
if a % (c * d) == 0:
    cd_num += 1

print(size - c_num - d_num + cd_num)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
if float(((B-A)/C)).is_integer():
  C_ = (B-A)//C
else:
  C_ = (B-A)//C+1

if float(((B-A)/D)).is_integer():
  D_ = (B-A)//D
else:
  D_ = (B-A)//D+1

if float(((B-A)/(C*D))).is_integer():
  CD_ = (B-A)//(C*D)
else:
  CD_ = (B-A)//(C*D)+1

#print(C_)
#print(D_)
#print(CD_)
print(B-A+1-C_-D_+CD_)

Submission status: Wrong Answer

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

def num_of_mod0(mod):
    if A%mod == 0:
        start = A
    else:
        start = (A//mod +1) * mod

    end = (B // mod) * mod

    return (end - start) / mod +1
for  j in [C,D,C*D]:    
    print(num_of_mod0(j))
ans  =(B-A+1)  - (num_of_mod0(C) + num_of_mod0(D) - num_of_mod0(C*D))

print(int(ans))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())
ans=B-A+1
E=C*D

if A%C==0:
    nC_initial=A//C
else:
    nC_initial=A//C+1
    
if A%D==0:
    nD_initial=A//D
else:
    nD_initial=A//D+1

    
if A%E==0:
    nE_initial=A//E
else:
    nE_initial=A//E+1
    
nC_final=B//C
nD_final=B//D
nE_final=B//E
#print(ans,nC_initial,nC_final,nD_initial,nD_final)
print(ans-(nC_final-nC_initial+1)-(nD_final-nD_initial+1)+(nE_final-nE_initial+1))

Submission status: Wrong Answer

Solution code:
line = input().split()
a,b,c,d = tuple([int(s) for s in line])

base = b-a+1

subb_c = int(b/c)
if a%c == 0:
    subm_c = int(a/c)
else:
    subm_c = int(a/c) + 1
c_count = subb_c - subm_c + 1

subb_d = int(b/d)
if a%d == 0:
    subm_d = int(a/d)
else:
    subm_d = int(a/d) + 1
d_count = subb_d - subm_d + 1

def gcd(m, n):
    while m%n != 0:
        temp = n
        n = m % n
        m = temp
    return n

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

mil = lcm(c, d)
subb_mil = int(b/mil)
if a%mil == 0:
    subm_mil = int(a/mil)
else:
    subm_mil = int(a/mil) + 1
mil_count = subb_mil - subm_mil + 1

base = base - c_count - d_count + mil_count

print(base)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

# A以上B以下値を割り切れるか調べる
count = 0
for i in range(A, B, 1):
    if not (i % C == 0 or i % D == 0):
        count += 1
print(count)

Submission status: Wrong Answer

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

import fractions
import math

x = b//c - math.ceil(a/c) + 1
y = b//d - math.ceil(a/d) + 1
e = c*d//fractions.gcd(c,d)
z = b//e - math.ceil(a/e) + 1

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

Submission status: Wrong Answer

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

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

first = ((B - A) // C) + 1
second = ((B - A) // D) + 1
third = ((B - A) // LCM) + 1

total = first + second - third

print((B - A - total + 1))

Submission status: Wrong Answer

Solution code:
#ユークリッド互除法！
def gcd(a,b):
  if(a<b):
    a,b=b,a
  if(b==0):
    return a
  c= a%b
  return gcd(b,c)

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

a_c=a//c
a_d=a//d
a_cd=a//(c*d/gcd(c,d))
a_ans=a-a_c-a_d+a_cd
#print(a_ans,a,a_c,a_d,a_cd)

b_c=b//c
b_d=b//d
b_cd=b//(c*d/gcd(c,d))
b_ans=b-b_c-b_d+b_cd
#print(b_ans,b,b_c,b_d,b_cd)

ans=1
if(a%c==0 or a%d==0):
  ans=0

print(int(b_ans-a_ans)+ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())
A -= 1
if C % 2 == 0 and D % 2 == 0:
    X = B//(C*D//2) - A//(C*D//2)
else:
    X = B//(C*D) - A//(C*D)
cc = B//C - A//C
dd = B//D - A//D
result = B - A - cc - dd + X
if C==D:
    result += cc
print(result)

Submission status: Wrong Answer

Solution code:
#import math
import fractions as math

def calc(n):
    if not A % n:
        a = A
    else:
        a = A + n - A % n

    if not B % n:
        b = B
    else:
        b  = B - (n - B % n)

    return a, b

A, B, C, D = list(map(int, input().split()))
n = []

for x in [C, D, int(((C*D)/math.gcd(C,D)))]:
    a, b = calc(x)
    n.append((b-a)//x + 1)

print(B-A+1-sum(n[0:2])+n[2])

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd


def read():
    A, B, C, D = list(map(int, input().strip().split()))
    return A, B, C, D


def solve(A, B, C, D):
    nC = math.floor(B / C) - math.ceil(A / C) + 1
    nD = math.floor(B / D) - math.ceil(A / D) + 1
    lcm = C * D / gcd(C, D)
    nCD = math.floor(B / lcm) - math.ceil(A / lcm) + 1
    return (B - A + 1) - (nC + nD - nCD)


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

Submission status: Wrong Answer

Solution code:
import fractions
import math


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


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

if d < c:
    tmp = c
    c = d
    d = tmp

common = lcm(c, d)

div_c = math.floor(b / c) - math.ceil(a / c) + 1
div_d = math.floor(b / d) - math.ceil(a / d) + 1
div_common = math.floor(b / common) - math.ceil(a / common) + 1
print((b - a) + 1 - div_c - div_d + div_common)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
x=0
for i in range(a,b):
  if i%c!=0 and i%d!=0:
    x=x+1
print(x)

Submission status: Wrong Answer

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

def lcm(a, b):
    return a * b / gcd(a, b)
A, B, C, D = map(int, input().split())
diff = B - A
ret = 0
if C == 1 or D == 1:
    print(0)
else:
    ret += diff // C
    if A % C == 0:
        ret += 1
    ret += diff // D
    if B % D == 0:
        ret += 1
    a = diff // int(lcm(C, D))
    print(diff-ret+a)

Submission status: Wrong Answer

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

a,b,c,d=(int(x) for x in input().split())
bs=lcm(c,d)
kihon=bs+1-(bs/c)-(bs/d)
saisyo=((a//bs)+1)*bs
saidai=(b//bs)*bs
count=kihon*(saidai-saisyo)/bs
ans=saisyo-a-(((saisyo-a)//c)+((saisyo-a)//d))+b-saidai-(((b-saidai)//c)+((b-saidai)//d))
print(math.floor(ans+count))

Submission status: Wrong Answer

Solution code:
# 逆に公倍数を引く。B-A+1-(Cの倍数の数+Dの倍数の数-CとDの公倍数の数)
# にぶたんで倍数の数を判定
# 1が含まれることに注意

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


def lcd(x, y):
    if x > y:
        return lcd(y, x)
    while x > 0:
        x, y = y % x, x
    return y


def gcm(x, y):
    return (x * y)/lcd(x, y)


def lower_bound(x, y):
    l, r = 0, 10 ** 18
    while l < r:
        mid = (l + r) // 2
        if x*mid > y:
            r = mid
        else:
            l = mid + 1
    return r


def upper_bound(x, y):
    l, r = 0, 10 ** 18
    while l < r:
        mid = (l + r) // 2
        if x*mid >= y:
            r = mid
        else:
            l = mid + 1
    return r


z = gcm(c, d)
c_l, c_r = upper_bound(c, a), upper_bound(c, b)
if c_r*c > b:
    c_r -= 1
d_l, d_r = upper_bound(d, a), upper_bound(d, b)
if d_r*d > b:
    d_r -= 1
z_l, z_r = upper_bound(z, a), upper_bound(z, b)
if z_r*z > b:
    z_r -= 1
# print(c_l, c_r, d_l, d_r, z_l, z_r)
print(b-a+1 - ((c_r-c_l+1)+(d_r-d_l+1)-(z_r-z_l+1)))

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

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


a,b,c,d = map(int, input().split())
div_c_min = math.ceil(a/c) * c
div_c_max = math.floor(b/c) * c
if div_c_max >= div_c_min:
  div_c_cnt = (div_c_max - div_c_min) / c + 1
else:
  div_c_cnt = 0
  
div_d_min = math.ceil(a/d) * d
div_d_max = math.floor(b/d) * d
if div_d_max >= div_d_min:
  div_d_cnt = (div_d_max - div_d_min) / d + 1
else:
  div_d_cnt = 0

lcm_cd = lcm(c,d)
div_cd_min = math.ceil(a/lcm_cd) * lcm_cd
div_cd_max = math.floor(b/lcm_cd) * lcm_cd
if div_cd_max >= div_cd_min:
  div_cd_cnt = (div_cd_max - div_cd_min) / lcm_cd + 1
else:
  div_cd_cnt = 0

#print(d,c,div_c_cnt,div_d_cnt,div_cd_cnt)
  
print(int(b - a + 1 - (div_c_cnt + div_d_cnt - div_cd_cnt)))

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
ans = 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 kosuu(x):
        global A,B
        return math.floor(B/x) - math.ceil(A/x) + 1

cn = kosuu(C)
dn = kosuu(D)
lc = lcm(C,D)
cdn = kosuu(lc)

print(B-A+1-(cn+dn-cdn))

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split())
diff = B - A + 1
count_c = int(B/C) - int((A-1)/C)
count_d = int(B/D) - int((A-1)/D)
cd = (C*D) // fractions.gcd(C,D)
count_cd = int(B/cd) - int((A-1)/cd)
print(diff - count_c - count_d + count_cd)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
s=b-a
bc=b//c
if a%c==0:
    ac=a//c-1
else:
    ac=a//c
bd=b//d
if a%d==0:
    ad=a//d-1
else:
    ad=a//d
e=c
f=d
while f:
    e, f = f, e % f
gcd=e
l=c*d/gcd
bl=b//l
if a%l==0:
    al=a//l-1
else:
    al=a//l
print(int(b-a+1-(bc-ac+bd-ad-bl+al)))

Submission status: Wrong Answer

Solution code:

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

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

E=C*D//gcd(C,D)
total=0
if A%C==0:
    total += B//C-A//C+1
else:
    total += B // C - A // C

if A%D==0:
    total += B//D-A//D+1
else:
    total += B // D - A  // D

if A%E==0:
    total = total- B//E-A//E+1
else:
    total = total - B // E - A // E

print(B-A+1-total)

Submission status: Wrong Answer

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

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

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

def keisan(s,e,d):
    if floor(s/d) != ceil(e/d):
        if s%d == 0:
            return floor(e/d) - floor(s/d) + 1
        else:
            return floor(e/d) - floor(s/d)
    elif e-s < d:
        return 0
    else:
        return 1

if B == A:
    if A%C == 0 or A%D == 0:
        print(0)
    else:
        print(1)
else:
    print(B-A+1-(keisan(A,B,C)+keisan(A,B,D)-keisan(A,B,lcm(C,D))))

Submission status: Wrong Answer

Solution code:
from fractions import gcd



a, b, c, d = map(int, input().split())
cd_gcd = gcd(c, d)
cd_lcm = c*d // cd_gcd
b_div_d = b // d
a_div_d = a // d
if a % d == 0:
    b_div_d += 1
b_div_c = b // c
a_div_c = a // c
if a % c == 0:
    b_div_c += 1
b_div_c_d = b // cd_lcm
a_div_c_d = a // cd_lcm
hoshugo_num = b_div_d - a_div_d + b_div_c - a_div_c - (b_div_c_d - a_div_c_d)
print(int(b - a + 1 - hoshugo_num))

Submission status: Wrong Answer

Solution code:

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(x, y):
    return (x * y) // gcd(x, y)

div1 = b//c - a//c

div2 = b//d - a//d

if a%c==0:
    div1 += 1
if a%d==0:
    div2 += 1

e = lcm(c,d)
div3 = b//e - a//e
ans = b-a+1 - div1 - div2 + div3
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
  while y != 0:
    x, y = y, x % y
  return x

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

c_div = int(b / c) - int((a - 1) / c)
d_div = int(b / d) - int((a - 1) / d)
lcm = int(c * d / gcd(c, d))
common = int(b / (lcm)) - int((a - 2) / (lcm))

print(b - a + 1 - c_div - d_div + common)

Submission status: Wrong Answer

Solution code:
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

A, B, C, D = map(int, input().split())  # A以上B以下の整数のうち、CでもDでも割り切れないものの個数

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

# B以下の全ての数でCで割れるものの個数hoge
hogeBC = int(B / C)
# A-1以下の全ての数でCで割れるものの個数fuga
fugaA1C = int((A-1) / C)

piyoBD = int(B / D)
toriA1D = int((A-1) / D)


yoshiBCD = int(B / (CD_lcm))
takaA1CD = int((A-1) / (CD_lcm))

# A以上B以下の整数でCで割り切れるものの個数
Ccan = hogeBC-fugaA1C

# A以上B以下の整数でDで割り切れるものの個数
Dcan = piyoBD - toriA1D

# A以上B以下の整数でCでもDでも割り切れるものの個数
CDcan = yoshiBCD - takaA1CD

print((B-(A-1)) - (Ccan+Dcan-CDcan))

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
def calc(x):
    return (int((B-A)/x)+1)
def gcd(m,n):
    if n==0:
        return m
    else:
        return gcd(n,m%n)
def lcm(m,n):
    return int(m*n/gcd(m,n))
print(B-A+1-calc(C)-calc(D)+calc(lcm(D,C)))

Submission status: Wrong Answer

Solution code:
#data=list(input().split())
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if a < b:
        temp = b
        b = a 
        a = temp
    remainder = a % b
    if remainder == 0:
        return b
    else:
        return gcd(remainder,b)

def gys(a,b):
    remainder = gcd(a,b)
    return int(a*b/remainder)

lcmm=gys(c,d)
def ans(n,k):
    return int(n/k)
def x(s):
    return ans(s,c)+ans(s,d)-ans(s,lcmm)
#print(x(b),x(a))
if a%c==0 or a%d==0:
    print(b-a-x(b)+x(a))
else:
    print(b-a+1-x(b)+x(a))

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
num = b-a+1
if a%c ==0:
        num1 = int(a/c)-1
else:
        num1 = int(a/c)
num2 = int(b/c)
numc = num2-num1
if a%d ==0:
        num3 = int(a/d) -1
else:
        num3 = int(a/d)
num4 = int(b/d)
numd = num4-num3
num_new = int((c*d)/fractions.gcd(c, d))
if a%num_new == 0:
        num5 = int(a/num_new)-1
else:
        num5 = int(a/num_new)
num6 = int(b/num_new)
numcd = num6-num5
print(num - numc - numd + numcd)

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
A, B, C, D = map(int, input().split())

v = B - A

x = v // C
y = v // D
z = v // lcm(C, D)
num = (v - (x + y - z))
    
print(num)

Submission status: Wrong Answer

Solution code:
import math

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

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

a, b, c, d = map(int, input().split())
ran = b - a + 1
if a % c == 0:
    count1 = math.ceil(ran / c)
else:
    count1 = math.ceil((ran - (c - a % c)) / c)
if a % d == 0:
    count2 = math.ceil(ran / d)
else:
    count2 = math.ceil((ran - (d - a % d)) / d)
e = lcm(c, d)
if a % e == 0:
    count3 = math.ceil(ran / e)
else:
    count3 = math.ceil((ran - (e - a % e)) / e)
print(ran - (count1 + count2 - count3))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


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


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

first_c = c * (a // c + 1) - (c - a % c)
last_c = c * b // c
first_d = d * (a // d + 1) - (d - a % d)
last_d = d * b // d
cd = lcm(c, d)
first_cd = cd * (a // cd + 1) - (cd - a % cd)
last_cd = cd * b // cd

cnum = 0
dnum = 0
cdnum = 0

if first_c <= b:
    cnum = (last_c - first_c) // c + 1

if first_d <= b:
    dnum = (last_d - first_d) // d + 1

if first_cd <= b:
    cdnum = (last_cd - first_cd) // cd + 1

total = cnum + dnum - cdnum
print(b - a + 1 - total)

Submission status: Wrong Answer

Solution code:
numbers = input().split(' ')

a = int(numbers[0])	
b = int(numbers[1])
c = int(numbers[2])
d = int(numbers[3])

count = 0
for i in range(a, b+1):
	if i % 2 == 0:
		continue
	if 	i % c != 0 and i % d != 0:
		count += 1
print(count)

Submission status: Wrong Answer

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

num_div_C = round(B / C + 0.5) - round(A / C + 0.5)
num_div_D = round(B / D + 0.5) - round(A / D + 0.5)
num_div_CD = round(B / (C * D) + 0.5) - round(A / (C * D) + 0.5)

print(B - A + 1 - (num_div_C + num_div_D - num_div_CD))

Submission status: Wrong Answer

Solution code:
import math
def hcf(a,b):
	if(b==0):
		return a
	if(a==0):
		return b
	return hcf(b,a%b)
a,b,c,d = list(map(int,input().split()))
cka = math.floor(b/c) - math.ceil(a/c) + 1
dka = math.floor(b/d) - math.ceil(a/d) + 1
lcm = (c*d)//(hcf(c, d))
# print("lcm",lcm)
dcka = math.floor(b/(lcm)) - math.ceil(a/(lcm)) + 1
# print(cka,dka,dcka)
print(b-a+1-cka-dka+dcka)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int, input().split())
sub=b-a
tmpc=sub//c
tmpd=sub//d
import fractions
def lcm(x,y):
    return (x*y) // fractions.gcd(x,y)
tmplcm=sub//lcm(c,d)
print(max(sub-(tmpc+tmpd-tmplcm), 0))

Submission status: Wrong Answer

Solution code:
import math

li = input().split()
a = int(li[0])
b = int(li[1])
c = int(li[2])
d = int(li[3])

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

B = 0
B += b//c
B += b//d
B -= b//lcm(c, d)

A = 0
A += a//c
A += a//d
A -= a//lcm(c, d)

ans = (b-a+1) - (B - A + (a%c == 0 or a%d == 0))
print(ans)
"""
print(0)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = [int(i) for i in input().split()]

if c == 1 or d == 1:
  print(0)
  exit()

c_left = [a // c - 1, a // c][a % c != 0]
c_right = b // c

c_number = c_right - c_left

d_left = [a // d - 1, a // d][a % d != 0]
d_right = b // d

d_number = d_right - d_left
cdgcd = (c * d) // fractions.gcd(c, d)

try:
    cd_left = [a // (cdgcd - 1), a // (cdgcd)][a % (cdgcd) != 0]
    cd_right = b // (cdgcd)
    cd_number = cd_right - cd_left
except:
    pass
  
print(b - a + 1 -  (c_number + d_number - cd_number))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if b>a:
        (a,b)=(b,a)
    c = int(a/b)
    d = a%b
    if d==0:
        return b
    else:
        return gcd(b,c)

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

count = 0
koubai = 0

while b-a+1>c*d-1:
    a += c*d
    koubai += 1

for i in range(a,b+1):
    if i%c != 0 and i%d != 0:
        count += 1

print(count+koubai*(c*d-c-d+gcd(c,d)))

Submission status: Wrong Answer

Solution code:
#最大公約数
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
#最小公倍数
def lcm(x,y):
    return (x*y//gcd(x,y))


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

if C==D:
    print(B+1-A-(B//C-A//C)-1)
else:
    c = (B+1)//C-A//C

    d = (B+1)//D-A//D

    e = (B+1)//CDlcm-A//CDlcm

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


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


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

first_c = c * (a // c + 1) - (c - a % c)
last_c = c * b // c
first_d = d * (a // d + 1) + (d - a % d)
last_d = d * b // d
cd = lcm(c, d)
first_cd = cd * (a // cd + 1) + (cd - a % cd)
last_cd = cd * b // cd

cnum = 0
dnum = 0
cdnum = 0

if first_c <= b:
    cnum = (last_c - first_c) // c + 1

if first_d <= b:
    dnum = (last_d - first_d) // d + 1

if first_cd <= b:
    cdnum = (last_cd - first_cd) // cd + 1

total = cnum + dnum - cdnum
print(b - a + 1 - total)

Submission status: Wrong Answer

Solution code:

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


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

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


a, b, c, d = acinput()
l = lcm(c, d)
CD = b//l-(a-1)//l
nC = b//c-(a-1)//c
nD = b//d-(a-1)//d

res = b-a+1-(nC+nD-CD)
print(int(res))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
x=b//c
y=b//d
z=b//(c*d / fractions.gcd(c,d))
xx=(a-1)//c
yy=(a-1)//d
zz=(a-1)//(c*d / fractions.gcd(c,d))
if c==1 or d==1:
    print(0)
elif a==b:
    if a%c==0 or a%d==0:
        print(0)
    else:
        print(1)
else:
    print(int(b-x-y+z-(a-1-xx-yy+zz)))

Submission status: Wrong Answer

Solution code:

def gcd(a,b):
  x = max([a,b])
  y = min([a,b])
  while y:
    x, y = y, x % y
  return x

# x * y = lcm(x, y) // gcd(x, y)より
def lcm(x, y):
  return x * y // gcd(x, y)


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

cd = lcm(c,d)
b_c = b // c
b_d = b // d
a_c = (a-1)//c
a_d = (a-1)//d
b_cd = b//(cd)
a_cd = a//(cd)
nums = b-a+1

#ans = nums - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd)
ans = (b - b_c - b_d + b_cd) - ((a-1) - a_c - a_d + a_cd)

print(ans)

Submission status: Wrong Answer

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

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

a, b, c, d = map(int, input().split())
count = 0
common = 0
dif = b - a
divC = dif // c
divD = dif // d
kobai = lcm(c, d)
divKobai = dif // kobai

#for i in range(a, b, c):
# for i in range(a, b + 1):
#     if i % c == 0 and i % d == 0:
#         common += 1

#print(dif - (divC + divD - common))
print(dif - (divC + divD - divKobai))

Submission status: Wrong Answer

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

e=b-a
print(e - int(e/c) - int(e/d) + int(b/(c*d)) )

Submission status: Wrong Answer

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

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

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

a = int((A - 1) / C)
b = int(B / C)

c = int((A - 1) / D)
d = int(B / D)

l = lcm(C, D)

e = int((A - 1) / l)
f = int(B / l)

if C == D:
    c = 0
    d = 0
    e = 0
    f = 0

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

print(res)

Submission status: Wrong Answer

Solution code:
#data=list(input().split())
a,b,c,d=map(int,input().split())
def gcd(a,b):
    if a < b:
        temp = b
        b = a 
        a = temp
    remainder = a % b
    if remainder == 0:
        return b
    else:
        return gcd(remainder,b)

def gys(a,b):
    remainder = gcd(a,b)
    return a*b/remainder

lcmm=gys(c,d)
def ans(n,k):
    return int(n/k)
def x(s):
    return ans(s,c)+ans(s,d)-ans(s,lcmm)
#print(x(b),x(a))
if a%c==0 or a%d==0:
    print(b-a-x(b)+x(a))
else:
    print(b-a+1-x(b)+x(a))

Submission status: Wrong Answer

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

print(
    B - A + 1
    - (B // C)
    - (B // D)
    + B // (C * D)
    + (A - 1) // C
    + (A - 1) // D
    - ((A - 1) // (C * D))
)

Submission status: Wrong Answer

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

c_div_a = a // c
c_div_all = b // c

d_div_a = a // d
d_div_all = b // d

cd_div_a = a // (c*d)
cd_div_all = b // (c*d)

div_a = c_div_a + d_div_a - cd_div_a
div_all = c_div_all + d_div_all - cd_div_all

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

Submission status: Wrong Answer

Solution code:

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

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

E=C*D//gcd(C,D)
total=0
if A%C==0:
    total += B//C-(A)//C+1
else:
    total += B // C - (A) // C

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

if A%E==0:
    total = total- B//E-A//E+1
else:
    total = total - B // E - A // E

print(B-A+1-total)

Submission status: Wrong Answer

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

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

def gcd(x, y):
    while y:
        x, y = y, x % y
    return int(x)

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

# A-1 以下の割り切れるものの個数
a_c = int((A-1) / C)
a_d = int((A-1) / D)
a_cd = int((A-1) / lcm(C, D))

# B以下の割り切れるものの個数
b_c = int(B / C)
b_d = int(B / D)
b_cd = int(B / lcm(C, D))

# A以上B以下の割り切れるものの個数
ab = (b_c + b_d - b_cd) - (a_c + a_d - a_cd)

# 割り切れないものの個数
ans = (B - A + 1) - ab

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

import math

def calc(x):
  left = math.ceil(A/x)*x
  right = math.floor(B/x)*x
  if A<=left<=right<=B:
    return (right - left) // x + 1
  else:
    return 0

from fractions import gcd

lcm = lambda a, b: a*b//gcd(a,b)

print((B-A)+1 - calc(C) - calc(D) + calc(lcm(C,D)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import fractions

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



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

lcm_cd = lcm_base(c, d)

print((b-a+1)-(b//c + b//d - b//lcm_cd) + ((a-1)//c + (a-1)//d - a//lcm_cd))