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:
A, B, C, D = map(int, input().split())

def abc131_c_v2(a,b,c,d):
    offset_c = c - a % c
    offset_c = offset_c if offset_c < c else 0
    offset_d = d - a % d
    offset_d = offset_d if offset_d < d else 0
    return b - a + 1 - len({x for x in range(a + offset_c,b+1,c)} | {x for x in range(a + offset_d,b+1,d)})

abc131_c_v2(A,B,C,D)

Submission status: Wrong Answer

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

def abc131_c(a,b,c,d):
    count = 0
    for i in range(a,b-1):
        if i % c == 0 or i % d == 0:
            continue
        count += 1
    return count
  
print(abc131_c(A,B,C,D))

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

NUM = B-A+1
CD = int((C*D)/fractions.gcd(C,D))

Ac = A
if Ac%C != 0:
  Ac += C-(Ac%C)

if B > Ac:
  DivC = math.ceil((B - Ac + 1)/C)
elif B == Ac:
  DivC = 1
else:
  DivC = 0


Ad = A
if Ad%D != 0:
  Ad += D-(Ad%D)

if B > Ad:
  DivD = math.ceil((B - Ad + 1)/D)
elif B == Ad:
  DivD = 1
else:
  DivD = 0

Acd = A
if Acd%CD != 0:
  Acd += CD-(Acd%CD)

if B > Acd:
  DivCD = math.ceil((B - Acd + 1)/CD)
elif B == Acd:
  DivCD = 1
else:
  DivCD = 0

print(NUM - DivC -DivD + DivCD)

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

NUM = B-A+1 #対象にしてる整数の個数
CD = int((C*D)/fractions.gcd(C,D))

if A%C == 0:
  DivC = math.ceil(NUM/C)
else:
  NUMC = NUM-(C-A%C)
  if NUMC > 0:
    DivC = math.ceil(NUMC/C)
  else :
    DivC = 0

if A%D == 0:
  DivD = math.ceil(NUM/D)
else:
  NUMD = NUM-(D-A%D)
  if NUMD > 0:
    DivD = math.ceil(NUMD/D)
  else :
    DivD = 0

if A%CD == 0:
  DivCD = math.ceil(NUM/CD)
else:
  NUMCD = NUM-(CD-A%CD)
  if NUMCD > 0:
    DivCD = math.ceil(NUMCD/CD)
  else :
    DivCD = 0


print(NUM - DivC -DivD + DivCD)

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

NUM = B-A+1 #対象にしてる整数の個数
CD = int((C*D)/fractions.gcd(C,D))

if A%C == 0:
  DivC = math.ceil(NUM/C)
else:
  NUMC = NUM-(C-A%C)
  DivC = math.ceil(NUMC/C)

if A%D == 0:
  DivD = math.ceil(NUM/D)
else:
  NUMD = NUM-(D-A%D)
  DivD = math.ceil(NUMD/D)

if A%CD == 0:
  DivCD = math.ceil(NUM/CD)
else:
  NUMCD = NUM-(CD-A%CD)
  DivCD = math.ceil(NUMCD/CD)


print(NUM - DivC -DivD + DivCD)

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

NUM = B-A+1 #対象にしてる整数の個数
CD = (C*D)//fractions.gcd(C,D)

if A%C == 0:
  DivC = math.ceil(NUM/C)
else:
  NUMC = NUM-(C-A%C)
  DivC = math.ceil(NUMC/C)

if A%D == 0:
  DivD = math.ceil(NUM/D)
else:
  NUMD = NUM-(D-A%D)
  DivD = math.ceil(NUMD/D)

if A%CD == 0:
  DivCD = math.ceil(NUM/CD)
else:
  NUMCD = NUM-(CD-A%CD)
  DivCD = math.ceil(NUMCD/CD)


print(NUM - DivC -DivD + DivCD)

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

NUM = B-A+1 #対象にしてる整数の個数
CD = (C*D)//fractions.gcd(C,D)

if A//C == 0:
  DivC = math.ceil(NUM/C)
else:
  NUMC = NUM-(C-A%C)
  DivC = math.ceil(NUMC/C)

if A//D == 0:
  DivD = math.ceil(NUM/D)
else:
  NUMD = NUM-(D-A%D)
  DivD = math.ceil(NUMD/D)

if A//CD == 0:
  DivCD = math.ceil(NUM/CD)
else:
  NUMCD = NUM-(CD-A%CD)
  DivCD = math.ceil(NUMCD/CD)


print(NUM - DivC -DivD + DivCD)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a,b,c,d = map(int,input().split())
count = (b-(b//c+b//d-b//(c*d/gcd(c,d)))) - ((a-1)-((a-1)//c+(a-1)//d-(a-1)//(c*d/gcd(c,d))))
print(int(count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0

for i in range(A, B+1):
  if i % (C*D) == 0:
    cnt += 1

print(cnt)

Submission status: Wrong Answer

Solution code:
import math

def gcd(p, q):
  if(q==0):
    return p
  else:
    return gcd(q, p%q)

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

def num_div(N, C, D):
  nC=math.floor(N/C)
  nD=math.floor(N/D)
  nCD=math.floor(N/lcm(C,D))
  return nC+nD-nCD

A, B, C, D=map(int, input().split())
M=num_div(B, C, D)-num_div(A-1, C, D)
ans=B-A+1-M
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
CD=C*D
l=[]
for i in [C,D,CD]:
    if A%i==0:
        l.append(B//i-A//i+1)
    else:
        l.append(B//i-A//i)
print(B-A+1-l[0]-l[1]+l[2])

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int,input().split())
g = C * D // fractions.gcd(C,D)
# A以下
cntA = 0
cntA += A // C
cntA += A // D
cntA -= A // g

# B未満
cntB = 0
cntB += (B-1) // C
cntB += (B-1) // D
cntB -= (B-1) // g

cnt = cntA - cntB
cnt = (A - B + 1) - cnt

print(cnt)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int,input().split())
g = C * D // fractions.gcd(C,D)
# A以下
cntA = 0
cntA += A // C
cntA += A // D
cntA -= A // g

# B未満
cntB = 0
cntB += B // C
cntB += B // D
cntB -= B // g

cnt = cntA - cntB
cnt = (A - B + 1) - cnt

print(cnt)

Submission status: Wrong Answer

Solution code:
import math
k = input().split()
a = int(k[0])
b = int(k[1])
c = int(k[2])
d = int(k[3])

CUpLimited = a/c
CDownLimited = b/c

DUpLimited = a/d
DDownLimited = b/d
# print((CDownLimited-CUpLimited))
# print((DDownLimited-DUpLimited))
Counter = b - a - int(CDownLimited-CUpLimited) - int(DDownLimited-DUpLimited)

print(math.floor(Counter))

Submission status: Wrong Answer

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

from functools import reduce
def gcd(a,b):
  if a < b:
    a, b = b, a
  while a % b != 0:
    a, b = b, a % b
  return b

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

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

gcd = lcm_list([c,d])

def solve(n):
	start = n * math.ceil(a / n)
	end = n * (b // n)
	#print(start,end)
	return (end - start) // n + 1

#print(solve(c),solve(d),solve(gcd))
ans = solve(c) + solve(d) - solve(gcd)
#print(ans)
print(b - a - ans + 1)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()
    if ans is not None:
        print(ans)


def solve():
    A, B, C, D = iip(False)

    a = B//C - (A-1)//C
    b = B//D - (A-1)//D
    c = B//(C*D) - (A-1)//(C*D)

    return B-A+1 -a-b+c



#####################################################ライブラリ集ここから

def iip(listed=True, num_only=True):
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def sort_tuples(l, index):
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):
    if index >= len(l):
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):
    return "".join(sorted(s))


def iip_ord(startcode="a"):
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):
    for i in s:
        print(i)


def bitall(N):
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret


def split_print_space(s):
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):
    print("\n".join([str(i) for i in s]))


def koenai_saidai_x_index(sorted_list, n):
    l = 0
    r = len(sorted_list)
    if len(sorted_list) == 0:
        return False
    if sorted_list[0] > n:
        return False

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] == n:
            return x
        elif sorted_list[x] > n:
            r = x
        else:
            l = x
    return l


def searchsorted(sorted_list, n, side="left"):
    if side not in ["right", "left"]:
        raise Exception("sideはrightかleftで指定してください")

    l = 0
    r = len(sorted_list)

    if n > sorted_list[-1]:
        # print(sorted_list)
        return len(sorted_list)
    if n < sorted_list[0]:
        return 0

    while r - l > 1:
        x = (l + r) // 2
        if sorted_list[x] > n:
            r = x
        elif sorted_list[x] < n:
            l = x
        else:
            if side == "left":
                r = x
            elif side == "right":
                l = x

    if side == "left":
        if sorted_list[l] == n:
            return r - 1
        else:
            return r

    if side == "right":
        if sorted_list[l] == n:
            return l + 1
        else:
            return l


def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod - 2)


def power(n, p, mod_=mod):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import fractions

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

f=fractions.gcd(c,d)
f2=c*d//f

p = b//c - (a-1)//c
q = b//d - (a-1)//d
r = b//(f2) - (a-1)//(f2)

Submission status: Wrong Answer

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

p = b//c - (a-1)//c
q = b//d - (a-1)//d
r = b//(c*d) - (a-1)//(c*d)


print((b-a+1) - (p+q-r))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# 方針
# 入力例1をよくみてみる。
# 1 2 3 4 5 6 7 8 9 10 11... に対して範囲[ 4, 9 ]の間で2の倍数を(),3の倍数を{}で示す
# 1 (2) {3} | (4) 5 {(6)} 7 (8) {9} | (10) 11.. となる。
# 範囲[1,9]の間の倍数で"ない"ものの個数と範囲[1,3]の間の倍数で"ない"ものの個数がわかれば良いことがわかる

# 範囲[ 1, upper ]の倍数で"ない"ものの個数
# Cの倍数とDの倍数を足してCDの倍数を引く。それらが倍数で"ある"ものの個数。
# よって戻り値は全体から倍数で"ある"ものの個数を引く
def get_non_div_cnt_with_range( upper ):
  num_of_range_with_C  = ( upper // C )
  num_of_range_with_D  = ( upper // D )
  num_of_range_with_CD = ( upper // ( C * D ))
  return upper - ( num_of_range_with_C + num_of_range_with_D - num_of_range_with_CD )

upper_limit = B
lower_limit = A - 1
  
print( get_non_div_cnt_with_range( upper_limit ) - get_non_div_cnt_with_range( lower_limit ) )

#どや！？

Submission status: Wrong Answer

Solution code:
import fractions
#なぜかWA
"""
A,B,C,D = list(map(int, input().split()))
cc = int(B/C) - int((A-1)/C)
dd = int(B/D) - int((A-1)/D)
cd = int(C*D / fractions.gcd(C,D))
ee = int(B/cd) - int((A-1)/cd)
U = B-A+1
print(U - (cc + dd - ee))
"""
#解説読んだ
#なんで通らなくぁｗせｄｒｆｔｇｙふじこｌｐ
A,B,C,D = list(map(int, input().split()))
def y(n, c, d):
    cd = int(c / fractions.gcd(c,d) * d)
    cc = int(n/c)
    dd = int(n/d)
    ee = int(n/cd)
    return n - cc - dd + ee

print(y(B, C, D) - y(A-1, C, D))

Submission status: Wrong Answer

Solution code:
import fractions
#なぜか動かない
"""
A,B,C,D = list(map(int, input().split()))
cc = int(B/C) - int((A-1)/C)
dd = int(B/D) - int((A-1)/D)
cd = int(C*D / fractions.gcd(C,D))
ee = int(B/cd) - int((A-1)/cd)
U = B-A+1
print(U - (cc + dd - ee))
"""
#解説読んだ
A,B,C,D = list(map(int, input().split()))
def y(n, c, d):
    cd = int(c*d / fractions.gcd(c,d))
    cc = int(n/c)
    dd = int(n/d)
    ee = int(n/cd)
    return n - cc - dd + ee

print(y(B, C, D) - y(A-1, C, D))

Submission status: Wrong Answer

Solution code:
import fractions

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

Submission status: Wrong Answer

Solution code:
import fractions

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

Submission status: Wrong Answer

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

dd = (B - int(B/D)) - (A - int(A/D))
ed = (B - int(B/(C*D))) - (A - int(A/(C*D)))
print(cd+dd-ed)

Submission status: Wrong Answer

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7

def main():
  A, B, C, D = map(int, readline().split())
  c = floor(B/C) - ceil(A/C) +1
  d = floor(B/D) - ceil(A/D) +1
  lcm = C*D/gcd(C,D)
  cd = floor(B/lcm) - ceil(A/lcm) +1
  ans = (B-A+1)-c-d+cd
  print(ans)
  
  
if __name__ == '__main__':
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B , C , D = map(int, input().split())
count= 0
bc = B // C 
bd = B // D
bcd = B //(C*D)
can = bc + bd - bcd
ans = B - can
ac = (A-1) // C
ad = (A-1) // D
acd = (A-1) //(C*D)
can2=  ac + ad - acd
ans = ans - ((A-1) - can2)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

cnt = 0
lcm = c * d // gcd(c, d)
a -= 1

under_b = b - (b//c + b//d - b//lcm)
under_a = a - (a//c + a//c - a//lcm)
answer = under_b - under_a

print(answer)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

cnt = 0
lcm = c * d / gcd(c, d)
a -= 1

under_b = b - (b//c + b//d) + b//lcm
under_a = a - (a//c + a//c) + a//lcm
answer = under_b - under_a

print(answer)

Submission status: Wrong Answer

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

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

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

print(B_ - A_)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

c_div = B//C - (A-1)//C
d_div = B//D - (A-1)//D
g = C*D // gcd(C, D)
cd_div = B//g - (A-1)//g
tot = B - A + 1
print(tot - c_div - d_div + cd_div)

print(tot, c_div, d_div, cd_div)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b,c,d = map(int, input().split())
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    if a==b:
        if a%c==0 or a%d==0:
            print(0)
        else:
            print(1)
    else:
        print(b - a - (b-a)//c - (b-a)//d + (b-a)//lcm(c,d))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    a,b,c,d = map(int, input().split())
    def gcd(a, b):
        if b == 0:
            return a
        else:
            return gcd(b, a % b)
    
    def gcd_group(arr):
        g = gcd(arr[0], arr[1])
        for i in range(2, len(arr)):
            g = gcd(g, arr[i])
        return g
    
    def lcm(a, b):
        g = gcd(a, b)
        return (a*b)//g
    
    def lcm_group(arr):
        l = lcm(arr[0], arr[1])
        for i in range(2, len(arr)):
            l = lcm(l, arr[i])
        return l
    
    print(b - a - (b-a)//c - (b-a)//d + (b-a)//lcm(c,d))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
k = input().split()
for i in range(len(k)):
    k[i] = int(k[i])
Counter = 0
# for i in range(k[0],k[1]):
#     if i%k[2] == 0:
#         continue
#     if i%k[3] == 0:
#         continue
#     Counter += 1
Buffer = 0
Factor = int(k[0]/k[2])+1
Factor2 = int(k[0]/k[3])+1
while(Buffer < k[1]):
    Buffer = k[2]*Factor
    Counter+=1
    Factor+=1

while(Buffer < k[1]):
    Buffer = k[3]*Factor
    Counter+=1
    Factor2+=1
print(k[1]-k[0]-Counter)

Submission status: Wrong Answer

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

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

gcd_num = lcm(c,d)

#a
a_count = a // c
a_count = a_count + (a//d)
a_count = a_count - (a//gcd_num)
a_count = a-a_count

#b
b_count = b // c
b_count = b_count + (b//d)
b_count = b_count - (b//gcd_num)
b_count = b-b_count

div = b-count-a_count
print(div)

Submission status: Wrong Answer

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

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

gcd_num = lcm(c,d)

#a
a_count = a // c
a_count = a_count + (a//d)
a_count = a_count - (a//gcd_num)

#b
b_count = b // c
b_count = b_count + (b//d)
b_count = b_count - (b//gcd_num)

print((b-a)-  b_count + a_count)

Submission status: Wrong Answer

Solution code:
import math
import fractions
EPS = 1e-5

def ceil(x):
    return math.ceil(x - EPS)
def floor(x):
    return math.floor(x + EPS)

def countX(X) :
    if X > B :
        return 0
    minX = ceil(A / X)
    maxX = floor(B / X)

    return maxX - minX + 1

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

ans = B - A + 1

# 最小公倍数
Z = C * D // fractions.gcd(C,D)

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import fractions
EPS = 1e-10

def ceil(x):
    return math.ceil(x - EPS)
def floor(x):
    return math.floor(x + EPS)

def countX(X) :
    if X > B :
        return 0
    minX = ceil(A / X)
    maxX = floor(B / X)

    return maxX - minX + 1

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

ans = B - A + 1

# 最小公倍数
Z = C * D // fractions.gcd(C,D)

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import fractions
EPS = 1e-14

def ceil(x):
    return math.ceil(x - EPS)
def floor(x):
    return math.floor(x + EPS)

def countX(X) :
    if X > B :
        return 0
    minX = ceil(A / X)
    maxX = floor(B / X)

    return maxX - minX + 1

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

ans = B - A + 1

# 最小公倍数
Z = C * D // fractions.gcd(C,D)

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import fractions
EPS = 1e-12

def ceil(x):
    return math.ceil(x - EPS)
def floor(x):
    return math.floor(x + EPS)

def countX(X) :
    if X > B :
        return 0
    minX = ceil(A / X)
    maxX = floor(B / X)

    return maxX - minX + 1

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

ans = B - A + 1

# 最小公倍数
Z = C * D // fractions.gcd(C,D)

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A,B,C,D = (int(x) for x in input().split())
E = A-1
F = (C * D) / gcd(C,D)
nc = B // C
nc2 = E // C
nd = B // D
nd2 = E // D
ncd = int(B // F)
ncd2 = int(E // F)
print(B-A+1-nc+nc2-nd+nd2+ncd-ncd2)

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd

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

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd

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

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque
import sys
import heapq
import bisect
import math
import itertools
import string
import queue
import copy
import time
from fractions import gcd
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

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

A, B, C, D = inp_list()
total = B - A + 1
ans = total - (total + 1) // C - (total + 1) // D + (total + 1) // lcm(C, D)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

s = b - a + 1
cc = b // c - (a - 1) // c
dd = b // d - (a - 1) // d
cd = b * a // gcd(a, b)
cd = b // cd + (a - 1) // cd
s -= cc + dd - cd
print(s)

Submission status: Wrong Answer

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

def gcd(x, y):
    if x < y:
        x, y = y, x
    while x % y != 0:
        x, y = y, x % y
    return x
a-=1
cd = c * d // gcd(c, d)
ans = b - (b // c) - (b // d) + (b // cd)
ans -= a - (a // c) - (a // d) + (a // cd)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import fractions

def solve(A: int, B: int, C: int, D: int):
    numCount = B - A + 1
    initialDivideC = -A%C+A + C
    initialDivideD = -A%D+A + D
    lcmCD = C*D//fractions.gcd(C,D)
    initialDivideLCM = -A%lcmCD+A + lcmCD
    countC = (B - initialDivideC)//C + 1
    if initialDivideC > B:
        countC = 0
    countD = (B - initialDivideD)//D + 1
    if initialDivideD > B:
        countD = 0
    countLCM = (B - initialDivideLCM)//lcmCD + 1
    if initialDivideLCM > B:
        countLCM = 0
    print(numCount - countC - countD + countLCM)
    return


# Generated by 1.1.6 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:
#!/usr/bin/env python3
import sys
import fractions


def solve(A: int, B: int, C: int, D: int):
    numCount = B - A + 1
    initialDivideC = A%C+A
    initialDivideD = A%D+A
    lcmCD = C*D//fractions.gcd(C,D)
    initialDivideLCM = A%lcmCD+A
    countC = (B - initialDivideC)//C + 1
    if initialDivideC > B:
        countC = 0
    countD = (B - initialDivideD)//D + 1
    if initialDivideD > B:
        countD = 0
    countLCM = (B - initialDivideLCM)//lcmCD + 1
    if initialDivideLCM > B:
        countLCM = 0
    print(numCount - countC - countD + countLCM)
    return


# Generated by 1.1.6 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:
#!/usr/bin/env python3
import sys
import fractions


def solve(A: int, B: int, C: int, D: int):
    numCount = B - A + 1
    initialDivideC = A%C+A
    initialDivideD = A%D+A
    lcmCD = C*D//fractions.gcd(C,D)
    initialDivideLCM = A%lcmCD+A
    countC = (B - initialDivideC)//C + 1
    if initialDivideC > B:
        countC -= 1
    countD = (B - initialDivideD)//D + 1
    if initialDivideD > B:
        countD -= 1
    countLCM = (B - initialDivideLCM)//lcmCD + 1
    if initialDivideLCM > B:
        countLCM -= 1
    print(numCount - countC - countD + countLCM)
    return


# Generated by 1.1.6 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:
#!/usr/bin/env python3
import sys
import fractions


def solve(A: int, B: int, C: int, D: int):
    numCount = B - A + 1
    initialDivideC = A%C+A
    initialDivideD = A%D+A
    lcmCD = C*D//fractions.gcd(C,D)
    initialDivideLCM = A%lcmCD+A
    countC = (B - initialDivideC)//C + 1
    countD = (B - initialDivideD)//D + 1
    countLCM = (B - initialDivideLCM)//lcmCD + 1
    print(numCount - countC - countD + countLCM)
    return


# Generated by 1.1.6 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:
# Euclidean Algorithm
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

# lcm (least common multiple)
def lcm(m, n):
    return m//gcd(m, n)*n

a, b, c, d = map(int, input().split())
ndiv = (b-a+1)//c + (b-a+1)//d - (b-a+1)//lcm(c,d)
print(b - a - ndiv)

Submission status: Wrong Answer

Solution code:
# Euclidean Algorithm (non-recursive)
def gcd2(m, n):
    while n:
        m, n = n, m % n
    return m

# lcm (least common multiple)
def lcm(m, n):
    return m//gcd2(m, n)*n

a, b, c, d = map(int, input().split())
ndiv = (b-a)//c + (b-a)//d - (b-a)//lcm(c,d)
print(b - a - ndiv )