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:
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())
if A%C==0:
    nc=int(B/C)-int(A/C)+1
else:
    nc=int(B/C)-int(A/C)
if A%D==0:
    #nd=int(B/C)-int(A/C)+1
    nd=int(B/D)-int(A/D)+1
else:
    nd=int(B/D)-int(A/D)
cd=C*D/gcd(C,D)
if A%cd==0:
    ncd=int(B/cd)-int(A/cd)+1
else:
    ncd=int(B/cd)-int(A/cd)
print(B-A+1-nc-nd+ncd)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())
if A%C==0:
    nc=int(B/C)-int(A/C)+1
else:
    nc=int(B/C)-int(A/C)
if A%D==0:
    nd=int(B/C)-int(A/C)+1
else:
    nd=int(B/D)-int(A/D)
cd=C*D/gcd(C,D)
if A%cd==0:
    ncd=int(B/cd)-int(A/cd)+1
else:
    ncd=int(B/cd)-int(A/cd)
print(B-A+1-nc-nd+ncd)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
def gcd(a,b):
    while b != 0:
        a, b = b, a%b
    return a
def lcm(a,b):
    return int(a*b / gcd(a,b))
X = A-B
Y = lcm(C,D)
i = B//C-(A-1)//C
j = B//D-(A-1)//D
k = B//Y-(A-1)//Y
print(Y)
print(int(B-A+1-(i+j-k)))

Submission status: Wrong Answer

Solution code:
import itertools as it
import collections as col
import fractions
from functools import reduce

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

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

Submission status: Wrong Answer

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

for i in range(A,B):
    x = i+1
    c = (i+1)%C
    d = (i+1)%D
    if A <= x:
        if c==0 or d==0:
            count += 1

print(B-A-count)

Submission status: Wrong Answer

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

for i in range(A,B):
    x = i+1
    c = (i+1)%C
    d = (i+1)%D
    if A <= x:
        if c==0 or d==0:
            count = count
        else:
            count += 1
print(count)

Submission status: Wrong Answer

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

from fractions import gcd

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

ac = int((a - 1) / c)
ad = int((a - 1) / d)
acd = int((a - 1) / lcm(c, d))

bc = int(b / c)
bd = int(b / d)
bcd = int(b / lcm(c, d))

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

Submission status: Wrong Answer

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

from fractions import gcd

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

ac = int(a / c)
ad = int(a / d)
acd = int(a / lcm(c, d))

bc = int(b / c)
bd = int(b / d)
bcd = int(b / lcm(c, d))

ans = (b - a + 1) - ((bc + bd - bcd) - (ac + ad - acd))
if (a % c == 0 or a % d == 0):
   ans -= 1
print(ans)

Submission status: Wrong Answer

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

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

def count(num, a, b):
    return num - num//a - num//b + num//lcm(a,b)

print(int(count(b,c,d)-count(a-1,c,d)))

Submission status: Wrong Answer

Solution code:
import fractions

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

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

lcm_n = lcm(c,d)

ans = (b - a-1) -((b-a-1)//c + (b-a-1)//d - (b-a-1) // lcm_n)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

lcm_n = lcm(c,d)

ans = b - a - (b-a)//c + (b-a)//d - (b-a) // lcm_n
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

lcm_n = lcm(c,d)

ans = (b - a) -((b-a)//c + (b-a)//d - (b-a) // lcm_n)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

lcm_n = lcm(c,d)

ans = (b - a) - ((b-a)//c + (b-a)//d - (b // lcm_n) - (a // lcm_n))
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

lcm_n = lcm(c,d)

ans = b - a -((b-a)//c + (b-a)//d - (b-a) // lcm_n)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
cnt_C = int(B // C) - int((A-1) // C)
cnt_D = int(B // D) - int((A-1) // D)
cnt_CD = int(B // ((C*D)/gcd(C,D))) - int((A-1) // ((C*D)/gcd(C,D)))
print(B - A + 1 - (cnt_C + cnt_D - cnt_CD))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
cnt_C = int(B // C) - int((A-1) // C)
cnt_D = int(B // D) - int((A-1) // D)
cnt_CD = int(B // ((C*D)/gcd(C,D))) - int(A // ((C*D)/gcd(C,D)))
print(B - A + 1 - (cnt_C + cnt_D - cnt_CD))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split(" "))
ans = 0
from fractions import gcd
def lcm(x, y):
  return (x * y) // gcd(x, y)
a -= 1
f = lcm(c,d)
ans = (b - a) - (b//c - a//c) + (b//d - a//d) - (b//f - a//f)

print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split(' ')))
def gcd(a, b):
    return b if a % b == 0 else gcd(b, a%b)
cd = d * (c // gcd(c, d))

right_c = b // c
right_d = b // d
right = b - right_c - right_d + (b // (cd))
left_c = a // c
left_d = a // d
left = a - left_c - left_d + (a // (cd))
hoge = (a % cd == 0) or (a % c != 0 and a % d != 0)
print(right - left + hoge)

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

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

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

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

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

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

bc = floor(B / C)
bd = floor(B / D)
bcd = floor(B / lcm)

ac = floor((A-1) / C)
ad = floor((A-1) / D)
acd = floor((A-1) / lcm)

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

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

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

bc = floor(B / C)
bd = floor(B / D)
bcd = floor(B / lcm)

ac = floor((A-1) / C)
ad = floor((A-1) / D)
acd = floor((A-1) / lcm)

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

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

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

bc = floor(B / C)
bd = floor(B / D)
bcd = floor(B / lcm)

ac = floor((A-1) / C)
ad = floor((A-1) / D)
acd = floor((A-1) / lcm)

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

Submission status: Wrong Answer

Solution code:
from math import floor

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

c = floor((B - A + 1) / C)
d = floor((B - A + 1) / D)
cd = floor((B - A + 1) / (C*D))

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

Submission status: Wrong Answer

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

import fractions

X = (C * D // fractions.gcd(C, D))
A -= 1 
ans = B - A  -  (B//C - A//C + B//D - A//D -(B//X + A//X)) 

print(ans)

Submission status: Wrong Answer

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

import fractions

X = (C * D // fractions.gcd(C, D))
A -= 1 
ans = B - A  -  (B//C - A//C + B//D - A//D -(B//X + A//X)) 

print(int(ans))

Submission status: Wrong Answer

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

import fractions

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

ans = B - A -  (B/C - A/C + B/D - A/D -(B/X + A/X)) 

print(int(ans))

Submission status: Wrong Answer

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

import fractions

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

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

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def lcm(c, d):
    c, d = max(c, d), min(c, d)
    cd = c * d
    while c % d > 0:
        c, d = d, c % d
    return cd // d

def solve():
    A, B, C, D = map(int, input().split())
    cd = lcm(C, D)
    divC = (B + 1) // C - A // C
    divD = (B + 1) // D - A // D
    divCD = (B + 1) // cd - A // cd
    print((B - A + 1) - (divC + divD - divCD))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
# coding: utf-8

(a, b, c, d) = [int(i) for i in input().rstrip().split(" ")]


def get_count(target: int):
    start = int(a / target) * target
    if start < a:
        start += target
    end = int(b / target) * target
    if end > b:
        end -= target
    if start > end:
        return 0
    return int((end - start) / target) + 1


def get_kouyaku(num1: int, num2: int):
    if num1 % num2 == 0:
        return num2
    return get_kouyaku(num2, num1 % num2)


def get_koubai(num1: int, num2: int):
    kouyaku = get_kouyaku(num1, num2)
    return kouyaku * int(num1 / kouyaku) * int(num2 / kouyaku)


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

print(ans)

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())
c=C*D/gcd(C,D)
b=B//C+B//D-B//c
a=(A-1)//C+(A-1)//D-(A-1)//c
print(int((B-b)-(A-1-a)))

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())
c=C*D/gcd(C,D)
b=B//C+B//D-B//c
a=(A-1)//C+(A-1)//D-(A-1)//c
print((B-b)-(A-1-a))

Submission status: Wrong Answer

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

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

cdiv = b//c - (a-1)//c
ddiv = b//d - (a-1)//d

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

print(b-a+1 - cdiv - ddiv + 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)
x = lcm
div = 0
while a <= x <= b:
    div += 1
    x  += lcm
    
cdiv = b//c - (a-1)//c
ddiv = b//d - (a-1)//d

print(b-a+1-cdiv-ddiv+div)

Submission status: Wrong Answer

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


ans = []
for i in (a-1,b):
  ans.append(int(i/c) + int(i/d) - int(i/lcm))

print(b-a - (ans[1]-ans[0]))

Submission status: Wrong Answer

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


ans = []
for i in (a,b):
  ans.append(int(i/c) + int(i/d) - int(i/lcm))

print(b-a - (ans[1]-ans[0]) + 1)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d= map(int,input().split())
n = b-a+1#要素数
j = b//c + b//d - (a-1)//c - (a-1)//d#a~bの範囲でcで割りきれる数とdで割り切れる数の合計
lcm =(c*d) / fractions.gcd(c,d)#c,dの最小公倍数
print(int(n-j+(b//lcm-(a-1)//lcm)))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d= map(int,input().split())
n = b-a+1#要素数
j = b//c + b//d - (a-1)//c - (a-1)//d#a~bの範囲でcで割りきれる数とdで割り切れる数の合計
lcm =(c*d) / fractions.gcd(c,d)#c,dの最小公倍数
print(int(n-j-(b//lcm-(a-1)//lcm)))

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(a,b):
  return (a*b)//gcd(a,b)
def main(a,b,c):
  if a%c==0 or b%c==0:
    s=((b-a)//c)+1
  else:
    s=(b-a)//c
  return s
S=main(A,B,C)
T=main(A,B,D)
U=main(A,B,lcm(C,D))
V=S+T-U
print(B-A+1-V)

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(a,b):
  return a*b//gcd(a,b)
def main(a,b,c):
  if a%c==0 or b%c==0:
    s=(b-a)//c+1
  else:
    s=(b-a)//c
  return s
S=main(A,B,C)
T=main(A,B,D)
U=main(A,B,lcm(C,D))
V=S+T-U
print(B-A+1-V)

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(a,b):
  return a*b//gcd(a,b)
s=(B-A)//C
t=(B-A)//D
u=(B-A)//lcm(C,D)
v=s+t-u
print(B-A+1-u)

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())
ac = a // c if a % c != 0 else a // c - 1
bc = b // c
ad = a // d if a % d != 0 else a // d - 1
bd = b // d
a_cd_dup = a // (lcm(c, d))
b_cd_dup = b // (lcm(c, d))
divisible_count = (bc - ac) + (bd - ad) - (b_cd_dup - a_cd_dup)
ans = (b - a + 1) - divisible_count
print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

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

def calc(n: int, x: int, y: int) -> int:
    return n - floor(n / x) - floor(n / y) + floor(n / lcm(x, y))


a, b, c, d = [int(i) for i in input().split()]
print(calc(b, c, d) - calc(a - 1, c, d))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b,c,d=mii()
c,d=min(c,d),max(c,d)

num = b-a+1

ac = (a-1)//c
bc = b//c 

ad = (a-1)//d
bd = b//d

cd = b //((c*d)//gcd(c,d))
if a!=b:
    print(num-(bc+bd-ac-ad)+cd)
else:
    if a%c==0 and a%d==0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b,c,d=mii()
c,d=min(c,d),max(c,d)

num = b-a+1

ac = (a-1)//c
bc = b//c 

ad = (a-1)//d
bd = b//d

cd = b //((c*d)//gcd(c,d))

print(num-(bc+bd-ac-ad)+cd)

Submission status: Wrong Answer

Solution code:
import fractions
def gcd(a,b):
   f=fractions.gcd(a,b)
   f2=a*b//f
   return f2

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

bc=b//c
bd=b//d
bcd=b//(gcd(c,d))

a=a-1

ac=a//c
ad=a//d
acd=a//(gcd(c,d))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

l, r, x, y = map(int, input().split())
lcm = x * y / gcd(x, y)

xn = r // x - (l - 1) // x
yn = r // y - (l - 1) // y
xyn = r // lcm - (l - 1) // lcm
print(r - l + 1 - xn - yn + xyn)

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd

l, r, x, y = map(int, input().split())
lcm = x * y / gcd(x, y)

xn = floor(r / x) - floor((l - 1) / x)
yn = floor(r / y) - floor((l - 1) / y)
xyn = floor(r / lcm) - floor((l - 1) / lcm)
print(r - l + 1 - xn - yn + xyn)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
S = B-A+1
C_count = S//C
D_count = S//D
both_count = S//(C*D)
hani = C_count + D_count - both_count
print(S-hani)

Submission status: Wrong Answer

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

c = C
d = D

gcd = 0
while gcd == 0:
  if c > d:
    k = c
    c = d
    d = k # 必ず c <= d になる
  if d%c == 0:
    gcd = c
  else:
    d = d%c

lcm = int(C*D/gcd)
#print(lcm)
ans = B - A + 1

CL = (-(-A // C))*C
CU = (B // C)*C
if CL <= CU:
  ans = ans - int((CU-CL)/C) - 1
#print(CL,CU,ans)
DL = (-(-A // D))*D
DU = (B // D)*D
if DL <= DU:
  ans = ans - int((DU-DL)/D) - 1
#print(DL, DU,ans)
lcmL = (-(-A // lcm))*lcm
lcmU = (B // lcm)*lcm
if lcmL <= lcmU:
  ans = ans + int((lcmU-lcmL)/lcm) + 1
#print(lcmL, lcmU)
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d  = map(int, input().split())
import fractions
divc = (b-a)//c
if a % c == 0:
    divc += 1
if b % c == 0:
    divc += 1
if a % c == 0 and b % c == 0:
    divc -= 1
if b-a<c:
    divc += 1

divd = (b-a)//d
if a % d == 0:
    divd += 1
if b % d == 0:
    divd += 1
if a % d == 0 and b % d == 0:
    divd -= 1   
if b-a<d:
    divd += 1

gcd = fractions.gcd(c,d)
cd = c * d // gcd
divcd = (b-a)//cd
if a % cd == 0:
    divcd += 1
if b % cd == 0:
    divcd += 1
if a % cd == 0 and b % cd == 0:
    divcd -= 1 
if b-a<cd:
    divcd += 1
wareru = divc + divd - divcd
ans = b - a - wareru +1
print(ans)

Submission status: Wrong Answer

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

def num(a,x):
  return (a-(a%x))//x

n=(b-a+1)-(num(b,c)-num(a-1,c))-(num(b,d)-num(a-1,c))+(num(b,lcm)-num(a-1,lcm))
print(n)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

c_count = b//c - (a-1)//c
d_count = b//d - (a-1)//d
cd_count = b//(c*d) - (a-1)//(c*d)

print(b-a+1-(c_count+d_count-cd_count))

Submission status: Wrong Answer

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

c_max = 0
d_max = 0
cd_max = 0

c_min = 0
d_min = 0
cd_min = 0

for i in reversed(data):
    if i%c == 0 and c_max == 0:
        c_max = i//c
    elif i%d == 0 and d_max == 0:
        d_max = i//d
    elif i%(c*d) == 0 and cd_max == 0:
        cd_max = i//(c*d)
    
    if c_max !=0 and d_max != 0 and cd_max != 0:
        break

for i in data:
    if i%c == 0 and c_min ==0 :
        c_min = i//c
    elif i%d == 0 and d_min ==0:
        d_min = i//d
    elif i%(c*d) == 0 and cd_min == 0:
        cd_min = i//(c*d)
    
    if c_min != 0 and d_min != 0 and cd_min != 0:
        break

c_count = c_max - c_min +1
d_count = d_max - d_min +1
cd_count = cd_max - cd_max +1

print(len(data)-(c_count+d_count-cd_count))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
dev = b- a +1
if dev % c==0:
    count = dev//c
else:
    if ((a%c)+(b%c)) < c:
        count = dev//c +1
    else:
        count = dev//c

if dev % d==0:
    count += dev//d
else:
    if ((a%d)+(b%d)) < d:
        count += dev//d +1
    else:
        count += dev//d

def lcm(c,d):
    return (c*d)//(fractions.gcd(c,d))
da = lcm(c,d)
if dev % (da)==0:
    count -= int(dev/(da))
else:
    if ((a%c)+(b%c)) < (da):
        count -= int(dev/(da)) 
    else:
        count -= int(dev/(da))
print(int(dev-count))

Submission status: Wrong Answer

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

p=a-((a//c)+(a//d)-(a//y))

q=b-((b//c)+(b//d)-(b//y))

print(int(q-p))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

x = c*d/fractions.gcd(c,d)
A = (a-1) - (a-1)//c - (a-1)//d + (a-1)//x
B = b - b//c - b//d + b//x
print(int(B-A))

Submission status: Wrong Answer

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

x = c*d/fractions.gcd(c,d)
A = (a-1) - (a-1)//c - (a-1)//d +x
B = b - (b-1)//c - (b-1)//d +x
print(int(B-A))

Submission status: Wrong Answer

Solution code:
"""
「A 以上 B 以下の整数のうち〜を満たすものの個数を求めよ」という問題では
(B 以下の整数のうちの〜を満たすものの個数) から
(A-1 以下の整数のうちの〜を満たすものの個数) を引く

- (全体)
+ (C の倍数の個数)
+ (D の倍数の個数)
- (C の倍数でも D の倍数でもあるものの個数)
"""

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

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
  
def u(n,C,D):
  return int(n - n//C - n//D + n//(C/gcd(C,D)*D))

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

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
#print(a,b,c,d)
total = b-a+1
#print(total)
lcm = c*d / fractions.gcd(c,d)
x = (b//c) + (b//d) - (b//lcm)
y = ((a-1)//c) + ((a-1)//d) - ((a-1)//lcm)
#print(x,y)
print(total - (x - y))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
print(a,b,c,d)
total = b-a+1
print(total)
lcm = c*d / fractions.gcd(c,d)
x = (b//c) + (b//d) - (b//lcm)
y = ((a-1)//c) + ((a-1)//d) - ((a-1)//lcm)
print(x,y)
print(total - (x - y))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
total = b-a+1
lcm = c*d / fractions.gcd(c,d)
x = (b//c) + (b//d) - (b//lcm)
y = ((a-1)//c) + ((a-1)//d) - ((a-1)//lcm)
#print(x,y)
print(int(total - (x - y)))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
total = b-a+1
lcm = c*d / fractions.gcd(c,d)
x = (b//c) + (b//d) - (b//lcm)
y = ((a-1)//c) + ((a-1)//d) - ((a-1)//lcm)
print(x,y)
print(int(total - (x - y)))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
total = b-a+1
lcm = c*d / fractions.gcd(c,d)
x = (b//c) - ((a-1)//c)
y = (b//d) - ((a-1)//d)
z = (b//lcm) - ((a-1)//lcm)
#print(x,y,z)
print(int(total - (x + y - z)))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
#print(a,b,c,d)
l = 0
for i in range(a,b+1):
    l += 1

#print(l)
lcm = c*d / fractions.gcd(c,d)
    
print(int(l - l//c -l//d + l//lcm))

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int, input().split())
#print(a,b,c,d)
l = []
for i in range(a,b+1):
    l.append(i)
#print(l)
lcm = c*d / fractions.gcd(c,d)
    
print(len(l) - len(l)//c -len(l)//d + len(l)//lcm)

Submission status: Wrong Answer

Solution code:
A, B, C, D = [int(n) for n in input().split()]
R = (B-A) if (B-A)%2 else (B+1-A)
a = R//C
b = R//D
c = R//(C*D)
print(R-(a+b-c))

Submission status: Wrong Answer

Solution code:
A, B, C, D = [int(n) for n in input().split()]
R = (B-A)
a = R//C
b = R//D
c = R//(C*D)
print(R-(a+b-c))

Submission status: Wrong Answer

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

ac_r = a % c
ad_r = a % d
acd_r = a % (c*d)
n = b - a + 1

if (ac_r == 0 and n % c == 1) or ((ac_r == 0 and n % c == 2) or (ac_r == 2 and n % c == 2)) :
    n_c = n // c + 1
else:
    n_c = n // c
    
if (ad_r == 0 and n % d == 1) or ((ad_r == 0 and n % d == 2) or (ad_r == 2 and n % d == 2)):
    n_d = n // d + 1
else:
    n_d = n // d
    
if (acd_r == 0 and n % (c*d) == 1) or ((acd_r == 0 and n % (c*d) == 2) or (acd_r == 2 and n % (c*d) == 2)):
    n_cd = n // (c*d) + 1
else:
    n_cd = n // (c*d)
    
print(n - (n_c + n_d - n_cd))

Submission status: Wrong Answer

Solution code:
def gcd(c, d):
  if c <= d:
    c, d = d, c
  while c % d:
    c, d = d, c % d
  return d
def lcm(c, d):
  return (c * d) // gcd(c, d)

A, B, C, D = map(int, input().split())
c_or_d = ((B // C) - (A // C)) + ((B // D) - (A // D)) - ((B // lcm(C, D)) - (A // lcm(C, D)))
print(B - A + 1 - c_or_d)

Submission status: Wrong Answer

Solution code:
def gcd(c, d):
  if c <= d:
    c, d = d, c
  while c % d:
    c, d = d, c % d
  return d
def lcm(c, d):
  return (c * d) // gcd(c, d)

A, B, C, D = map(int, input().split())
c_or_d = (B // C - A // C) + (B // D - A // D) -(B // lcm(C, D) - A // lcm(C, D))
print(B - A + 1 - c_or_d)

Submission status: Wrong Answer

Solution code:
def gcd(c, d):
  if c <= d:
    c, d = d, c
  while c % d:
    c, d = d, c % d
  return d
def lcm(c, d):
  return c*d // gcd(c, d)

A, B, C, D = map(int, input().split())
c_or_d = (B//C - A//C) + (B // D - A // D) -(B // lcm(C, D) - A // lcm(C, D))
print(B - A + 1 - c_or_d)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A, B, C, D = map(int, input().split())
BdivC, BdivD = B // C, B // D
AdivC, AdivD = (A - 1) // C, (A - 1) // D
GCD = gcd(C, D)
BdivCD, AdivCD = B // ((C * D) // GCD), (A - 1) // ((C * D) // GCD)
N1 = BdivC + BdivD - BdivCD
N2 = AdivC + AdivD - AdivCD
ans = (B - A) - (N1 - N2)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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


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


def search(n, i, j):
    l = lcm(i, j)
    return n - int(n / i) - int(n / j) + int(n / l)


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

Submission status: Wrong Answer

Solution code:
import fractions
def lcm(A, B):
    return int((A * B) / fractions.gcd(A, B))
A, B, C, D = map(int, input().split())
length = B - A
cc = length // C
dd = length // D
ll = length // lcm(C, D)
print(length - cc - dd + ll)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce


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


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


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


A, B, C, D = map(int, input().split())
ans_b = B - int(B / C) - int(B / D) + int(B / lcm_base(C, D))
B = A - 1
ans_a = B - int(B / C) - int(B / D) + int(B / lcm_base(C, D))
print(ans_b - ans_a)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())
def quo_items(x, num1, num2):
    num1_quo = x // num1
    num2_quo = x // num2
    num12_quo = x // (num1 / gcd(num1, num2) * num2)
    items = x - num1_quo - num2_quo + num12_quo
    return items

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())
def quo_items(x, num1, num2):
    num1_quo = int(x // num1)
    num2_quo = int(x // num2)
    num12_quo = int(x // (num1 / gcd(num1, num2) * num2))
    items = x - num1_quo - num2_quo + num12_quo
    return items

print(int(quo_items(b, c, d) - quo_items(a - 1, c, d)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())
def quo_items(x, num1, num2):
    num1_quo = int(x // num1)
    num2_quo = int(x // num2)
    num12_quo = int(x // (num1 * num2 / gcd(num1, num2)))
    items = x - num1_quo - num2_quo + num12_quo
    return items

print(int(quo_items(b, c, d) - quo_items(a - 1, c, d)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
length = B + 1 - A
ans = length
CD = C * D
if A % C == 0:
    add_c = 0
else:
    add_c = C - A % C
ans -= (length - add_c) // C

if A % D == 0:
    add_d = 0
else:
    add_d = D - A % D
ans -= (length - add_d) // D

if A % CD == 0:
    add_cd = 0
else:
    add_cd = CD - A % CD
ans += (length - add_cd) // CD
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#cとdの最小公倍数eを求める
import fractions
e = int(c*d/fractions.gcd(c,d))
#1からeまでの個数ans_eを求める
ans_e = 0
for i in range(1,e):
    if ((i%c) * (i%d)) !=0:
        ans_e += 1
#aからn*eまでの個数ans_aと、 m*eからbまでの個数ans_bを求める
n = a//e+1
m = b//e
if n > m:
    ans = 0
    for i in range(a,b+1):
        if ((i%c) * (i%d)) !=0:
            ans+=1
    print(ans)
else:
    ans_a = 0
    ans_b = 0
    for i in range(a,e*(a//e+1)):
        if ((i%c) * (i%d)) !=0:
            ans_a += 1
    for i in range(e*(b//e),b):
        if ((i%c) * (i%d)) !=0:
            ans_b += 1
    #(m-n)*ans_e + ans_a +ans_bが答え
    print((m-n)*ans_e + ans_a +ans_b)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
min = min(C, D)
max = max(C, D)
c=0
d=0
e=0

def gcd(max, min):
  while min:
    max, min = min, max%min
  return max
lcm = max*min//gcd(max,min)
c = B//C-A//C
d = B//D-A//D
if lcm <= A:
  e = B//lcm-(-(-A//lcm))
else:
  e = B//lcm
print(c)
print(d)
print(e)

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
min = min(C, D)
max = max(C, D)
c=0
d=0
e=0

def gcd(max, min):
  while min:
    max, min = min, max%min
  return max
lcm = max*min//gcd(max,min)
if A>=C:
  c = B//C-(-(-A//C))+1
if A>=D:
  d = B//D-(-(-A//D))+1
if B>=lcm:
  e = B//lcm-(-(-A//lcm))+1
print(c)
print(d)
print(e)

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
c=0
d=0
e=0
if A>=C:
  c = B//C-(-(-A//C))
if A>=D:
  d = B//D-(-(-A//D))
if B>=(C*D):
  e = B//(C*D)-(-(-A//(C*D)))

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

Submission status: Wrong Answer

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