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:
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Bad")
    elif q == 0:print("Good")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

#n = ip()                                     #入力整数1つ
a,b,c,d= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(m)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
if min(c,d) == 1:
    print(0)
if a == b:
    if a%c and a%d:
        print(1)
    else:print(0)
elif min(a,b)+1 == max(a,b):
    s =0
    if a%c and a%d:s+=1
    if b%c and b%d:s+=1
    print(s)
else:
    sub1 = (b+1)//d - a//d
    sub2 = (b+1)//c - a//c
    inter = lcm(c,d)
    sub3 = (b+1)//inter - a//inter
    ans = b-a+1-sub1-sub2+sub3
    if b%inter == 0:
        ans-=1
    if a%inter == 0:
        ans-=1
    if a%inter == 0 and b%inter == 0:
        ans+=1
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def lcm(m,n):
    return m*n/gcd(m,n)
def f2(temp3):
    return (B-A+1)-(int(B/temp3)-int((A-1)/temp3))

temp=lcm(C,D)


print(f2(C)+f2(D)-f2(temp))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
ans = b - a + 1#ok
a -= 1#ok

g = gcd(c,d)
n = c / g
m = d / g
temp = n*m*g

cc = -int(a/c) + int(b/c)
dd = -int(a/d) + int(b/d)
cd = -int(a/temp) + int(b / temp)

if c == 1 or d == 1:
    print(0)
elif max(c,d)%min(c,d) == 0:
    if c > d:
        print(ans - dd)
    else:
        print(ans - cc)
else:
    print(ans - cc - dd + cd)

Submission status: Wrong Answer

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

Cprimes = {}
Dprimes = {}

tmpC = C
d = 2
while tmpC > 1:
    if tmpC % d == 0:
        if d in Cprimes:
            Cprimes[d] += 1
        else:
            Cprimes[d] = 1
        tmpC //= d
    else:
        d += 1

tmpD = D
d = 2
while tmpD > 1:
    if tmpD % d == 0:
        if d in Dprimes:
            Dprimes[d] += 1
        else:
            Dprimes[d] = 1
        tmpD //= d
    else:
        d += 1

comPrimes = {}
for k in Cprimes:
    comPrimes[k] = Cprimes[k]
for k in Dprimes:
    if k in comPrimes and comPrimes[k] < Dprimes[k]:
        comPrimes[k] = Dprimes[k]
    else:
        comPrimes[k] = Dprimes[k]

#print(Cprimes)
#print(Dprimes)
#print(comPrimes)
comVal = 1
for k in comPrimes:
    comVal *= k**comPrimes[k]

#print(comVal)

CdivNum = B//C - (A-1)//C
DdivNum = B//D - (A-1)//D
comDivNum = B//comVal - (A-1)//comVal
ans = B-(A-1)
ans -= CdivNum
ans -= DdivNum
ans += comDivNum

print(ans)

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().strip().split())

a_c = A // C
a_c_mod = A % C
b_c = B // C
a_d = A // D
a_d_mod = A % D
b_d = B // D

l = lcm(C, D)

a_cd = A // l
a_cd_mod = A % l
b_cd = B // l

if a_c_mod == 0:
    a_c -= 1

if a_d_mod == 0:
    a_d -= 1

if a_cd_mod == 0:
    a_cd -= 1

print((B - A + 1) - (b_c - a_c) - (b_d - a_d) + (b_cd + a_cd))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

num_c = (-c*(math.ceil(a/c))+c*(b//c))//c+1
num_d = (-d*(math.ceil(a/d))+d*(b//d))//d+1
num_e = (-e*(math.ceil(a/e))+e*(b//e))//e+1
print( b-a+1-num_c - num_d +num_e)

Submission status: Wrong Answer

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

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

a, b, c, d = list(map(int, input().split()))
ttt = lcm(c, d)
tt, ta, tb, tc = b-a+1, (b-a+1)//c, (b-a+1)//d, (b-a+1)//ttt
if (b-a+1)%c:
  ta += 1
if (b-a+1)%d:
  tb += 1
if a<=ttt<b and (b-a+1)%ttt:
  tc += 1
if c==d:
  tb = 0
  tc = 0
print(tt-ta-tb+tc)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions
 
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
  
a, b, c, d = [int(elem) for elem in input().split()]
print((b+1 - a) - ((b+1) // c) - ((b+1) // d) + (a // c) + (a // d) + ((b+1) // lcm(c, d)) - (a // lcm(c, d)))

Submission status: Wrong Answer

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

"""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 // (memo2)

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


main()

Submission status: Wrong Answer

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

def ans(v1,v2,v3):
    return v1-v1//v2-v1//v3+v1//(v2*v3/fractions.gcd(v2,v3))
print(int(ans(B,C,D)-ans(A-1,C,D)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

a, b, c, d = map(int, input().split())
g = lcm(c, d)
alpha = a % c
count_c = (b - a + 1 + alpha) // c
alpha = a % d
count_d = (b - a + 1 + alpha) // d
alpha = a % g
count_g = (b - a + 1 + alpha) // g

s = b - a + 1 - count_c - count_d + count_g

print(s)

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)

round=lambda x:(x*2+1)//2

a, b, c, d = map(int, input().split())
x = b - a + 1
n = int(round(x / c))
m = int(round(x / d))
LCM = lcm(c, d)
l = int(round(x / LCM))
print(x - n - m + l)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
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 anti_division_iter(a, b, r):
    n = b // r
    m = (a-1) // r
    return n - m

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

div_c = anti_division_iter(a, b, c)
div_d = anti_division_iter(a, b, d)
div_cd = anti_division_iter(a, b, lcm(c, d))
print(div_c, div_d, div_cd)

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

Submission status: Wrong Answer

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

sub = B - A + 1
cDivNum = int(sub / C)
dDivNum = int(sub / D)
cdDivNum = int(sub /(C*D))

#print(sub,cDivNum,dDivNum,cdDivNum)
print(sub - (cDivNum+dDivNum-cdDivNum))

Submission status: Wrong Answer

Solution code:
# coding:utf-8


def main():
    # N = int(input())
    A, B, C, D = map(int, input().split())
    length = B - A + 1
    divc = B//C - A//C
    if A % C == 0:
        divc += 1

    divd = B//D - A//D
    if A % D == 0:
        divd += 1
    divcd = B//(C*D) - A//(C*D)
    if A % (C*D) == 0:
        divcd += 1
    # print(divc, divd, divcd)

    ans = length - divc - divd + divcd

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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


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

p  = B - A + 1 - int((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // s - (A - 1) // s))
print(p)

Submission status: Wrong Answer

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

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

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

#tgC = int(B/C) - int((A-1)/C)
#tgD = int(B/D) - int((A-1)/D)
#tgCD = int(B/CD) - int((A-1)/CD)

tgC = math.floor(B/C) - math.floor((A-1)/C)
tgD = math.floor(B/D) - math.floor((A-1)/D)
tgCD = math.floor(B/CD) - math.floor((A-1)/CD)

print((B-A+1)-(tgC+tgD-tgCD))

Submission status: Wrong Answer

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

ans=0
gc=c*d/gcd(c,d)

if a%c==0:
    ans-=1
if a%d==0:
    ans-=1
if a%gc==0:
    ans+=1
ans+=(b-a+1)-(int(b/c)+int(b/d)-int(a/c)-int(a/d)-int(b/gc)+int(a/gc))

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions


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

G = C * D / fractions.gcd(C,D)

ans = int(( B // C - (A-1) // C ) + (B // D - (A-1) // D) - (B // G - (A-1) // G))

print (B - A + 1 - ans)

Submission status: Wrong Answer

Solution code:
a=list(map(int,input().split()))
k=0
for i in range(a[0],a[1]):
  if i/a[2]!=i//a[2]:
    if i/a[3]!=i//a[3]:
      k+=1
  else:
    k+=0
print(k)

Submission status: Wrong Answer

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

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

print(counter)

Submission status: Wrong Answer

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

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

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

l_c = int((a-1)/c)
l_d = int((a-1)/d)
l_c_d = int((a-1)/lcm(c, d))

l_ans = a - 1 - (l_c + l_d - l_c_d)


g_c = int(b/c)
g_d = int(b/d)
g_c_d = int(b/lcm(c, d))
g_ans = b - (g_c + g_d - g_c_d)

print(g_ans - l_ans)

Submission status: Wrong Answer

Solution code:
import math

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

if C > D :
    C , D = D , C


# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X >= B :
        return 0
    minX = math.ceil(A / X)
    maxX = math.floor(B / X)

    return maxX - minX

ans = B - A + max(0,C - A) - countX(C) - countX(D) + countX(C * D)

print(ans)

Submission status: Wrong Answer

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

# A
Ax = A // (C * D)
Ay = A // C
Az = A // D
AA = Ay + Az -Ax
a = A - AA
# B
Bx = B // (C * D)
By = B // C
Bz = B // D
BB = By + Bz -Bx
b = B - BB

print(b - a)

Submission status: Wrong Answer

Solution code:
def dfs(k):
    if k==-1:return 0
    if a==1:
        return int(b/k)
    else:
        return int(b/k)-int((a-1)/k)
a,b,c,d=map(int,input().split())
e=-1
for i in range(max(c,d),b):
    if i%c==0 and i%d==0:
        e=i
ans=b-a+1-dfs(c)-dfs(d)+dfs(e)
print(ans)

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

if div != 1:
    x_div = a//div
    y_div = b//div
else:
    x_div = 0
    y_div = 0
x_c = a//c
if a%c == 0:
    x_c -=1
y_c = b//c
x_d = a//d
if a%d == 0:
    x_d -= 1
y_d = b//d
print(b-a+1+(y_div-x_div)-(y_c-x_c)-(y_d-x_d))

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def number_calc(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    return (right - left + 1)

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

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

print(ans)

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
  return (right - left) // x + (1 if A<=left<=right<=B else 0)

from fractions import gcd

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

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

Submission status: Wrong Answer

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

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

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

numCD = B//CD - A//CD
numAll = B - A + 1
print(numAll - numC - numD + numCD)

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 * b // gcd(a, 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(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義

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


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

diffs = B - A

ma = max(C,D)
mi = min(C,D)

#if ma % mi == 0:
#    mi_num = (diffs) // mi
#    print(diffs - mi_num)
#    exit()



C_num = (diffs) // C
D_num = (diffs) // D

#C_num = (diffs - (A % C)) // C
#D_num = (diffs - (A % D)) // D
sc = lcm(C,D)


sum_num = (diffs ) // sc
#sum_num = (diffs - (A % sc)) // sc


print(diffs - (C_num + D_num - sum_num))

Submission status: Wrong Answer

Solution code:
from heapq import heappush, heappop, heapify, heapreplace
from collections import defaultdict
from bisect import bisect_left
from math import floor, ceil


class Solution:
    def gcd(self, a, b):
        while b:
            a, b = b, a % b
        return a
    
    def lcm(self, a, b):
        return a * b // self.gcd(a, b)

    def main(self):
        A, B, C, D = map(int, input().split())
        v = self.lcm(C, D)
        c_and_d =  floor(B/(v)) - ceil(A/(v)) + 1
        only_c = floor(B/(C)) - ceil(A/(C)) + 1
        only_d = floor(B/(D)) - ceil(A/(D)) + 1
        res = (B - A + 1) - (only_c + only_d - c_and_d)
        print(res)

if __name__ == '__main__':
    Solution().main()

Submission status: Wrong Answer

Solution code:
import fractions

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

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

ac = A // C
bc = B // C
ad = A // D
bd = B // D
alcm = A // lcm
blcm = B // lcm

num_c = bc - ac
num_d = bd - ad
num_lcm = blcm - alcm

print("%d %d %d" % (num_c, num_d, num_lcm))

ans = B - A - (num_c + num_d - num_lcm) + 1

print(ans)

Submission status: Wrong Answer

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


def divs_count(start, end, mod):
    return (end // mod) - ceil(start / mod) + 1


def gcd(x, y):
    m = min(x, y)
    n = max(x, y)
    if m == 0:
        return n
    return gcd(m, n % m)


def solve(A: int, B: int, C: int, D: int):
    ans = (
        B
        - A
        + 1
        - (
            divs_count(A, B, C)
            + divs_count(A, B, D)
            - divs_count(A, B, (C * D) // gcd(C, D))
        )
    )
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
t = b//c-a//c
u = b//d-a//d
if a%c == 0:
  t += 1
if a%d == 0:
  u += 1
def gcd(p,q):
    if p%q != 0:
        return gcd(q,p%q)
    else:
        return q
k = c*d//gcd(c,d)
v = b//k-a//k
if a != b:
  if c != 1 and d != 1:
    print(b-a+1-t-u+v)
  else:
    print(0)
else:
  if a%c == 0:
    print(0)
  elif a%d == 0:
    print(0)
  else:
    print(1)

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

print(int(b-x-y+z-(a-1-xx-yy+zz)))

Submission status: Wrong Answer

Solution code:
import fractions

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

# l = lcm(c,d)
g = fractions.gcd(c, d)
l = int((c * d) / g)

def num(x, y, z): #x以上y以下でzで割り切れる数の個数
    ent = int((x + z - 1) / z)
    att = int(y / z)
    return att - ent + 1

gyaku = num(a, b, c) + num(a, b, d) - num(a, b, l)
print(b - a + 1 - gyaku)

Submission status: Wrong Answer

Solution code:


(A,B,C,D) = (int(i) for i in input().split(" "))
c = C
d = D
if c > d:
	d += c
	c = d-c
	d = d-c
while d%c!=0:
	d = d%c
	d += c
	c = d-c
	d = d-c
E = C/c*D
print(B-A+1-int(B/C)+int((A-1)/C)-int(B/D)+int((A-1)/D)+int(B/E)-int((A-1)/E))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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 x

def lcm(x, y):
    return 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
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) + 1
    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 math
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


DIV = 10**9+7

def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret
    
def mod_modify(a,mod):
    return (a+mod)%mod

def cal_ABC(A,B,C):
    AC = math.ceil(A/C)
    BC = (B//C)
    return max(BC-AC+1,0)


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

def main():
    ans =0
    A,B,C,D = ints_raw()
    total = B-A+1
    dC = cal_ABC(A,B,C)
    dD = cal_ABC(A,B,D)
    dCD = cal_ABC(A,B,C*D//gcd(C,D))    
    return total-dC-dD+dCD

print(main())

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int, input().split())
ab=b-a
C=ab//c
D=ab//d
E=ab//(c*d//fractions.gcd(c, d))
print(ab-C-D+E)

Submission status: Wrong Answer

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


com=lcm(c, d)
tmp=math.floor(b/com)-math.floor(a/com)
print(count+tmp)

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

c = B // C - A // C
d = B // D - A // D
cd = B // lcm(C, D) - A // lcm(C, D)

num = c + d - cd
ans = B - A - num + 1
print(ans)

Submission status: Wrong Answer

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

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
  return (right - left) // x + (1 if left<=A<=B<=right else 0)

from fractions import gcd

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from math import ceil
lcm = lambda x, y: x * y // gcd(x, y)
def solve():
    a, b, c, d = map(int, input().split())
    C = len(range(ceil(a / c) * c, b + 1, c))
    if c == d:
        return b - a + 1 - C
    D = len(range(ceil(a / d) * d, b + 1, d))
    cd = lcm(c, d)
    CD = len(range(ceil(a / cd) * cd, b + 1, cd))
    return b - a + 1 - (C + D - CD)
print(solve())

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
count = 0
area = B-A+1
count += int(area/C)
if (A%C + area%C) >=C:
    count+=1
count += int(area/D)
if (A%D + area%D) >=D:
    count+=1
E = C*D
count -= int(area/E)
if (A%E + area%E) >=E:
    count-=1

print(area-count)

Submission status: Wrong Answer

Solution code:
def main():
    A, B, C, D = [int(n) for n in input().split()]
    min_c = A // C if A % C == 0 else (A // C)+1
    max_c = B // C if B % C == 0 else (B // C)
    min_d = A // D if A % D == 0 else (A // D)+1
    max_d = B // D if B % D == 0 else (B // D)
    min_pro = A // (C*D) if A % (C*D) == 0 else (A // (C*D))+1
    max_pro = B // (C*D) if B % (C*D) == 0 else (B // (C*D))
    

    print((B-A+1) - (max_c-min_c+1) - (max_d-min_d+1) + (max_pro-min_pro + 1))
main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

def prime_cd(n,c,d):
    c_div=n//c
    d_div=n//d
    lcm=c*d//gcd(c,d)
    cd_div=n//lcm
    return n-c_div-d_div+cd_div

print(prime_cd(b,c,d)-prime_cd(a,c,d))

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
if a==b and a%c!=0 and a%d!=0:
  print(0)
else:
  cd = int(c*d/fractions.gcd(c, d))
  waru_c = int(b/c)-int((a-1)/c)
  waru_d = int(b/d)-int((a-1)/d)
  waru_cd = int(b/cd)-int((a-1)/cd)
  print((b-a+1)-(waru_c+waru_d-waru_cd))

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
gcd = 0
if C>D:
  big = C
  small = D
else:
  big = C
  small = D
GCDa = big
while GCDa != 0:
  GCD = GCDa
  tmp = small
  small = big%small
  big = tmp
  GCDa = small
gcd = C*D/GCD
ans = int(B-A+1-((B//C-(A-1)//C)+(B//D-(A-1)//D)-(B//gcd-(A-1)//gcd)))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

cd = (C * D) / fractions.gcd(C, D)
bc = int(B / C)
bd = int(B / D)
bcd = int(B / cd)
ac = int((A-1) / C)
ad = int((A-1) / D)
acd =int((A-1) / cd)

print((B - bc - bd + bcd) - (A-1 - ac - ad + acd))

Submission status: Wrong Answer

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

def gcd(p, q):
    if q > p:
        p, q = q, p
    m = -1
    while m != 0:
        m = p % q
        p, q = q, m
    return p

a = a - 1
lcm = c * d / gcd(d, c)
dc = b//c - a//c
dd = b//d - a//d
dcd = b//lcm - a//lcm
divable = dc + dd - dcd
print(b - a - divable)

Submission status: Wrong Answer

Solution code:
# C問題
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())
E = lcm(C, D)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
e=(b-a)//c
f=(b-a)//d 
ans=(b-a+1)-(e+f)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
L = c*d/gcd(c,d)
def f(x):
  return int(b//x-(a-1)//x)
print(b-a+1-f(c)-f(d)+f(L))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def main():
    a,b,c,d = map(int,input().split(" "))
    n = b - a + 1

    noinclude = int(a/c) + int(a/d) - int(a/(c * d / gcd(c, d)))
    include = int(b/c) + int(b/d) - noinclude - int(b/(c * d / gcd(c, d)))
    print(n - include)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def solve(n1,n2):
    k = gcd(n1,n2)
    return (n1*n2)/k

l = solve(c,d)

ans1 = b - int(b//c) - int(b//d) + int(b//l)
ans2 = a - int(a//c) - int(a//d) + int(a//l)

print(int(ans1-ans2))

Submission status: Wrong Answer

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

cko = math.floor(b/c) - math.ceil(a/c) + 1
dko = math.floor(b/d) - math.ceil(a/d) + 1
cdko = math.floor(b/e) - math.ceil(a/e) + 1
print(b-a+1-cko-dko+cdko)

Submission status: Wrong Answer

Solution code:
import math

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

if C > D :
    C , D = D , C

ans = B - A

ans += max(0,C - A)

# A以上B以下の数でCの倍数の個数
minC = max(math.ceil(A / C),0)
maxC = max(math.floor(B / C),1)
ans -= maxC - minC

minD = max(math.ceil(A / D),0)
maxD = max(math.floor(B / D),1)
ans -= maxD - minD

CD = C * D
minCD = max(math.ceil(A / CD),0)
maxCD = max(math.floor(B / CD),1)
ans += maxCD - minCD


print(ans)