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 gcd(a,b):
  while b:
    a, b = b, a%b
  return a

def lcm(x,y):
  return x/gcd(x,y)*y
  
ans = (B - B//C - B//D + B//lcm(C,D) ) - ( (A-1) - (A-1)//C - (A-1)//D + (A-1)//lcm(C,D) )
print(ans)

Submission status: Wrong Answer

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

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

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

if C<D:
  t=C
  C=D
  D=t
  
ans = (B - B//C - B//D + B//lcm(C,D) ) - ( (A-1) - (A-1)//C - (A-1)//D + (A-1)//lcm(C,D) )
print(int(ans))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

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)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

a,b,c,d = map(int,input().split())
count = 0
lcm = c * d // fractions.gcd(c, d)
cb = int(b / c)
ca = int((a-1) / c)
db = int(b / d)
da = int((a-1) / d)
lcmb = int(b / lcm)
lcma = int((a-1)/lcm)
count = b - a + 1 - (cb-ca+db-da-lcmb+lcma)
print(count)

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)


num = b//c - a//c 
if a//c == a/c:
  num +=1
num_2 = b//d - a//d
if a//d == a/d:
  num_2 += 1
num_3 = b//lcm(c,d) - a//lcm(c,d)
if a//lcm(c,d) == a/lcm(c,d):
  num_3 +=1
num__ = num + num_2 - num_3

print(b-a+1-num__)

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)


num = b//c - a//c 
if a//c == a/c:
  num +=1
print(num)
num_2 = b//d - a//d
if a//d == a/d:
  num_2 += 1
print(num_2)
num_3 = b//lcm(c,d) - a//lcm(c,d)
if a//lcm(c,d) == a/lcm(c,d):
  num_3 +=1
print(num_3)
num__ = num + num_2 - num_3

print(b-a+1-num__)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
if A == B:
    print(0)
else:
    def gcd(a,b):
        while b!=0:
            a,b=b,a%b
        return a

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

    if A%C == 0:
        AC = int(A/C) - 1
    else:
        AC = int(A/C)
    if A%D == 0:
        AD = int(A/D) - 1
    else:
        AD = int(A/D)

    lcmCD = lcm(C,D)
    if A%lcmCD == 0:
        ACD = int(A/lcmCD) - 1
    else:
        ACD = int(A/lcmCD)

    ans = (B - A + 1) - (int(B/C) - AC + int(B/D) - AD - int(B/lcmCD) + ACD)
    
    print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
if A == B:
    print(0)
else:
    def gcd(a,b):
        while b!=0:
            a,b=b,a%b
        return a

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

    if A%C == 0:
        AC = int(A/C) - 1
    else:
        AC = int(A/C)
    if A%D == 0:
        AD = int(A/D) - 1
    else:
        AD = int(A/D)

    lcmCD = lcm(C,D)
    if A%(lcmCD) == 0:
        ACD = int(A/(lcmCD)) - 1
    else:
        ACD = int(A/(lcmCD))

    ans = (B - A + 1) - (int(B/C) - AC + int(B/D) - AD - int(B/lcmCD) + ACD)

    print(ans)

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 a*b/gcd(a,b)

if A%C == 0:
    AC = int(A/C) - 1
else:
    AC = int(A/C)
if A%D == 0:
    AD = int(A/D) - 1
else:
    AD = int(A/D)
    
lcmCD = lcm(C,D)
if A%(lcmCD) == 0:
    ACD = int(A/(lcmCD)) - 1
else:
    ACD = int(A/(lcmCD))
    
ans = (B - A + 1) - (int(B/C) - AC + int(B/D) - AD - int(B/lcmCD) + ACD)

print(ans)

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 a*b/gcd(a,b)

if A%C == 0:
    AC = int(A/C) - 1
else:
    AC = int(A/C)
if A%D == 0:
    AD = int(A/D) - 1
else:
    AD = int(A/D)
    
lcmCD = lcm(C,D)
if A%(lcmCD) == 0:
    ACD = int(A/(lcmCD)) - 1
else:
    ACD = int(A/(lcmCD))
    
ans = (B - A + 1) - (int(B/C) - AC + int(B/D) - AD - int(B/(lcmCD) + ACD))

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

if A%C == 0:
    AC = int(A/C) - 1
else:
    AC = int(A/C)
if A%D == 0:
    AD = int(A/D) - 1
else:
    AD = int(A/D)
    
lcmCD = lcm(C,D)
if A%(lcmCD) == 0:
    ACD = int(A/(lcmCD)) - 1
else:
    ACD = int(A/(lcmCD))
    
print(int((B - A + 1) - (int(B/C) - AC + int(B/D) - AD - int(B/(lcmCD) + ACD))))

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def nearUpNum (num, div):
    if num % div == 0:
        return num
    else:
        return num - num % div

def nearDownNum(num, div):
    if num % div == 0:
        return num
    else:
        return num + (div - num % div)

def euqlid(x,y):
    if x < y :
        temp = x
        x = y
        y = temp
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y
n = (c * d) / euqlid(c,d)
C = (((nearUpNum(b,c) - nearDownNum(a,c)) / c) + 1)
D = (((nearUpNum(b,d) - nearDownNum(a,d)) / d) + 1)
CandD = (((nearUpNum(b, n) - nearDownNum(a, n)) / n) + 1)
print(int((b - a + 1) - (C + D - CandD)))

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def nearUpNum (num, div):
    if num % div == 0:
        return num
    else:
        return num - num % div

def nearDownNum(num, div):
    if num % div == 0:
        return num
    else:
        return num + (div - num % div)

def euqlid(x,y):
    if x < y :
        temp = x
        x = y
        y = temp
    while x % y != 0:
        temp = x
        x = y
        y = temp % y
    return y
n = (c * d) / euqlid(c,d)
C = (((nearUpNum(b,c) - nearDownNum(a,c)) / c) + 1)
D = (((nearUpNum(b,d) - nearDownNum(a,d)) / d) + 1)
CandD = (((nearUpNum(b, n) - nearDownNum(a, n)) / n) + 1)
print("C =>  {}:D =>  {}:CandD => {}".format(C,D,CandD))
print(int((b - a + 1) - (C + D - CandD)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def getAns(a, b, c):
  num_c = b // c - a // c
  return num_c

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

# cについて
num_c =getAns(a,b,c)
#print(num_c)

# dについて
num_d =getAns(a,b,d)
#print(num_d)

# cとdの公倍数について
cd = c * d // gcd(c,d)
num_cd = getAns(a,b,cd)
#print(num_cd)

print(b - a + 1 - (num_c + num_d - num_cd))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

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

# 割り切れる数を探す


left_c = a // c if a% c != 0 else (a // c) - 1
right_c = b // c

c_count = right_c - left_c

left_d = a // d if a % d != 0 else (a // d) - 1
right_d = b // d

d_count = right_d - left_d


lcm_cd = int(c * d / fractions.gcd(c, d))

left_cd = a // (lcm_cd) if a // (lcm_cd) != 0 else a // (lcm_cd) - 1
right_cd = b // (lcm_cd)

cd_count = right_cd - left_cd

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

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split())
Max = B-A+1
CD = C*D//(fractions.gcd(C, D))
Ccount = B//C-A//C
Dcount = B//D-A//D
CDcount = B//CD-A//CD
if B % C == 0:
    Ccount += 1
if B % D == 0:
    Dcount += 1
if B % CD == 0:
    CDcount += 1
count = Max+CDcount-Ccount-Dcount

print(count)

Submission status: Wrong Answer

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

gcd = 0
e = c
f = d
if e > f:
  e, f = f, e
while (True):
  r = f % e
  if r == 0:
    gcd = e
    break
  else:
    e, f = r, e

lcm = int(c * d / gcd)
ac = int((a - 1)/c)
ad = int((a - 1)/d)
al = int((a - 1)/lcm)
bc = int(b/c)
bd = int(b/d)
bl = int(b/lcm)

div_able = (bc - ac) + (bd - ad) - (bl - al)
div_disable = (b - a + 1) - div_able

print(div_disable)

Submission status: Wrong Answer

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

gcd = 0
e = c
f = d
if e > f:
  e, f = f, e
while (True):
  r = f % e
  if r == 0:
    gcd = e
    break
  else:
    e, f = r, e

lcm = int(c * d / gcd)
ac = int((a - 1)/c)
ad = int((a - 1)/d)
bc = int(b/c)
bd = int(b/d)
al = int((a - 1)/lcm)
bl = int(b/lcm)

div_able = (bc - ac) + (bd - ad) - (bl - al)
div_disable = (b - a + 1) - div_able

print(div_disable)

Submission status: Wrong Answer

Solution code:
import math

print("test")

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = list(map(int, input().split()))
lcm = c * d / gcd(c,d)
#Bの要素
c0 = b//c
d0 = b//d
lcm0 = b//lcm
#Aの要素
c1 = (a-1)//c
d1 = (a-1)//d
lcm1 = (a-1)//lcm
ans = (b - c0 - d0 + lcm0) - (a - 1 - c1 - d1 + lcm1)
print(int(ans))

Submission status: Wrong Answer

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

# get lcc which will be i*c
i = 0
flg = True

while (flg):
  i += 1
  flg = ((c * i) % d != 0)
  

lcc = i * c
ac = int((a - 1)/c)
ad = int((a - 1)/d)
bc = int(b/c)
bd = int(b/d)
al = int((a - 1)/lcc)
bl = int(b/lcc)

div_able = (bc - ac) + (bd - ad) - (bl - al)
div_disable = (b - a + 1) - div_able

print(div_disable)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = list(map(int, input().split()))
lcm = c * d / gcd(c,d)
#Bの要素
c0 = b//c
d0 = b//d
lcm0 = b//lcm
#Aの要素
c1 = (a-1)//c
d1 = (a-1)//d
lcm1 = (a-1)//lcm
ans = (b - c0 - d0 + lcm0) - (a - 1 - c1 - d1 + lcm1)
print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor
from math import ceil
from fractions import gcd
a, b, c, d = tuple(int(i) for i in input().split(" "))


def num_divided_in_n(n):
    return (floor(b / n) * n - ceil(a / n) * n) / n + 1


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


print(max(0, int(b - a + 1 - (num_divided_in_n(c) +
                       num_divided_in_n(d) - num_divided_in_n(lcm(c, d))))))

Submission status: Wrong Answer

Solution code:
from math import floor
from math import ceil
from fractions import gcd
a, b, c, d = tuple(int(i) for i in input().split(" "))


def num_divided_in_n(n):
    return (floor(b / n) * n - ceil(a / n) * n) / n + 1


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


print(int(b - a + 1 - (num_divided_in_n(c) +\
                       num_divided_in_n(d) - num_divided_in_n(lcm(c, d)))))

Submission status: Wrong Answer

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

countC = (B // C) - (A // C) + 1
countD = (B // D) - (A // D) + 1
def lcm(x, y):
    return (x * y) // frac.gcd(x, y)
lcmCD = lcm(C, D)
countlcm = (B // lcmCD) - (A // lcmCD) + 1

num = B - A + 1

print(num - countC - countD + countlcm)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def lcm(C, D):
    return int(C * D // gcd(C, D))


main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
def input(): return sys.stdin.readline().strip()
a,b,c,d=map(int,input().split())
def count(start, end, x):
    return math.floor(end/x) - math.ceil(start/x) + 1
print(b-a+1-(count(a,b,c) + count(a,b,d) - count(a,b,c*d//gcd(c,d))))

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
def input(): return sys.stdin.readline().strip()
a,b,c,d=map(int,input().split())
def count(start, end, x):
    return math.floor(end/x) - math.ceil(start/x) + 1
print(b-a+1-(count(a,b,c) + count(a,b,d) - count(a,b,c*d/gcd(c,d))))

Submission status: Wrong Answer

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

List = [int(x) for x in input().split()]
A = List[0]
B = List[1]
C = List[2]
D = List[3]

if A%C == 0:
    C_low = int(A/C)
else:
    C_low = int(A/C)+1

if B%C == 0:
    C_upp = int(B/C)
else:
    C_upp = int(B/C)-1

if A%D == 0:
    D_low = int(A/D)
else:
    D_low = int(A/D)+1

if B%D == 0:
    D_upp = int(B/D)
else:
    D_upp = int(B/D)-1

count = 0

for i in range(C_low,C_upp+1):
    count += 1

for j in range(D_low,D_upp+1):
    count += 1

for i in range(C_low,C_upp+1):
    for j in range(D_low,D_upp+1):
        if C*i == D*j:
            count -= 1

print(B-A-count)

Submission status: Wrong Answer

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

countC = (B // C) - (A // C)
countD = (B // D) - (A // D)
def lcm(x, y):
    return (x * y) // frac.gcd(x, y)
lcmCD = lcm(C, D)
countlcm = (B // lcmCD) - (A // lcmCD)
#print(countC)
#print(countD)
#print(countlcm)

num = B - A + 1

print(num - countC - countD + countlcm)

Submission status: Wrong Answer

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

countC = (B // C) - (A // C)
countD = (B // D) - (A // D)
def lcm(x, y):
    return (x * y) // frac.gcd(x, y)
lcmCD = lcm(C, D)
countlcm = (B // lcmCD) - (A // lcmCD)
print(countC)
print(countD)
print(countlcm)

num = B - A + 1

print(num - countC - countD + countlcm)

Submission status: Wrong Answer

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

countC = (B // C) - (A // C)
countD = (B // D) - (A // D)
def lcm(x, y):
    return (x * y) // frac.gcd(x, y)
lcmCD = lcm(C, D)
countlcm = (B // lcmCD) - (A // lcmCD)

num = B - A

print(num - countC - countD + countlcm)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int, input().split())
L=D
M=C
if M < L:
    M, L = L, M
while M % L != 0:
    M, L = L, M % L
K=L
E=int((C*D)//K)
F=int(A//E)
G=int(B//E)
H=int(E//C+E//D-1)
I=int((E*(F+1)-A)//C+(E*(F+1)-A)//D)
J=int((B-(E*G))//C+(B-(E*G))//D)
print(B-A-((G-F-1)*H+I+J))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if a<b:a,b=b,a
    while a%b!=0:
        a,b=b,a%b
    return b
def ko(k):
    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=c*d/gcd(c,d)
print(b-a+1-ko(c)-ko(d)+ko(e))

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = input().strip().split(" ")
A = int(A)
B = int(B)
C = int(C)
D = int(D)
X = int(C / int(fractions.gcd(C,D))) * D

A -= 1
ans1 = A - (int(A/C) + int(A/D) - int(A/X))
ans2 = B - (int(B/C) + int(B/D) - int(B/X))

print(ans2 - ans1)

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = input().strip().split(" ")
A = int(A)
B = int(B)
C = int(C)
D = int(D)
X = int(C / int(fractions.gcd(C,D)) * D)

A -= 1
ans1 = A - (int(A/C) + int(A/D) - int(A/X))
ans2 = B - (int(B/C) + int(B/D) - int(B/X))

print(ans2 - ans1)

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = input().strip().split(" ")
A = int(A)
B = int(B)
C = int(C)
D = int(D)
X = int(C / int(fractions.gcd(C,D)) * D)

ans1 = A - (int(A/C) + int(A/D) - int(A/X))
ans2 = B - (int(B/C) + int(B/D) - int(B/X))

print(ans2 - ans1)

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = input().strip().split(" ")
A = int(A)
B = int(B)
C = int(C)
D = int(D)
X = int(C / int(fractions.gcd(C,D)) * D)

ans1 = A - (A//C + A//D - A//X)
ans2 = B - (B//C + B//D - B//X)

print(ans2 - ans1)

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = input().strip().split(" ")
A = int(A)
B = int(B)
C = int(C)
D = int(D)
X = int(C*D / int(fractions.gcd(C,D)))

ans1 = A - (A//C + A//D - A//X)
ans2 = B - (B//C + B//D - B//X)

print(ans2 - ans1)

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = input().strip().split(" ")
A = int(A)
B = int(B)
C = int(C)
D = int(D)
X = int(C*D / int(fractions.gcd(C,D)))

if( (A-1) == 0 ):
    div1 = 0
    div2 = 0
    div5 = 0
else:
    div1 = int((A-1) / C)
    div2 = int((A-1) / D)
    div5 = int((A-1) / X)

if( (B-1) == 0 ):
    div3 = 0
    div4 = 0
    div6 = 0
else:
    div3 = int(B / C)
    div4 = int(B / D)
    div6 = int(B / X)

result = (B - div3 - div4 + div6) - (A-1 - div1 - div2 + div5)

print(result)

Submission status: Wrong Answer

Solution code:
import fractions

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

div1 = int((A-1) / C)
div2 = int((A-1) / D)
div3 = int(B / C)
div4 = int(B / D)

X = int(C*D / int(fractions.gcd(C,D)))
div5 = int((A-1) / X)
div6 = int(B / X)

result = (B - div3 - div4 + div6) - (A-1 - div1 - div2 + div5)

print(result)

Submission status: Wrong Answer

Solution code:
import fractions

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

div1 = int((A-1) / C)
div2 = int((A-1) / D)
div3 = int(B / C)
div4 = int(B / D)

X = int(C*D / int(fractions.gcd(C,D)))
print(X)
div5 = int((A-1) / X)
div6 = int(B / X)

print(div1,div2,div3,div4,div5,div6)
result = (B - div3 - div4 + div6) - (A-1 - div1 - div2 + div5)

print(result)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
import fractions
E=(C * D) //fractions.gcd(C, D)
c=1/C
d=1/D
e=1/E
if A % C ==0:
  C_min=int(A*c)
else:
  C_min=int(A*c)+1
C_max=int(B*c)
if A % D ==0:
  D_min=int(A*d)
else:
  D_min=int(A*d)+1

if A % (C*D) ==0:
  CD_min=int(A*e)
else:
  CD_min=int(A*e)+1

D_max=int(B*d)
CD_max=int(B*e)+1
M=C_max-C_min+D_max-D_min-(CD_max-CD_min)

print(B-A-1-M)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
"""解説
B以下の整数のうち、CでもDでも割り切れないものの個数をCountBとする
A以下の整数のうち、CでもDでも割り切れないものの個数をCountAとする

求める答えは、CountB - CountA

・CountBの求め方
B以下の整数のうち、Cで割り切れるものの個数はCountB_C = B//C
B以下の整数のうち、Dで割り切れるものの個数はCountB_D = B//D
B以下の整数のうち、CでもDでも割り切れるものの個数はCountB_CD = B//lcm(C,D)

CountB = B - (CountB_C + CountB_D - CountB_CD)

"""
from fractions import gcd
from math import floor

def solve():
    A, B, C, D = list(map(int, input().split()))
    def lcm(a, b):
        """ aとbの最小公倍数を返す """
        return a*b // gcd(a, b)

    def f(x):
        """ 1以上x以下の整数のうち、CでもDでも割り切れないものの個数を返す """
        return x - (floor(x/C) + floor(x/D) - floor(x/lcm(C,D)))
        #return x - (x//C + x//D - x//lcm(C,D))

    ans = f(B) - f(A-1)

    print(int(ans))


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
"""解説
B以下の整数のうち、CでもDでも割り切れないものの個数をCountBとする
A以下の整数のうち、CでもDでも割り切れないものの個数をCountAとする

求める答えは、CountB - CountA

・CountBの求め方
B以下の整数のうち、Cで割り切れるものの個数はCountB_C = B//C
B以下の整数のうち、Dで割り切れるものの個数はCountB_D = B//D
B以下の整数のうち、CでもDでも割り切れるものの個数はCountB_CD = B//lcm(C,D)

CountB = B - (CountB_C + CountB_D - CountB_CD)

"""
from fractions import gcd
from math import floor

def solve():
    A, B, C, D = list(map(int, input().split()))
    def lcm(a, b):
        """ aとbの最小公倍数を返す """
        return a*b // gcd(a, b)

    def f(x):
        """ 1以上x以下の整数のうち、CでもDでも割り切れないものの個数を返す """
        return x - (floor(x/C) + floor(x/D) - floor(x/lcm(C,D)))

    ans = f(B) - f(A-1)

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
import fractions
E=(C * D) //fractions.gcd(C, D)
c=1/C
d=1/D
e=1/E
C_min=int(A*c)+1
C_max=int(B*c)
D_min=int(A*d)+1
D_max=int(B*d)
CD_min=int(A*e)+1
CD_max=int(B*e)+1
M=C_max-C_min+D_max-D_min-(CD_max-CD_min)
print(B-A-1-M)

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
"""解説
B以下の整数のうち、CでもDでも割り切れないものの個数をCountBとする
A以下の整数のうち、CでもDでも割り切れないものの個数をCountAとする

求める答えは、CountB - CountA

・CountBの求め方
B以下の整数のうち、Cで割り切れるものの個数はCountB_C = B//C
B以下の整数のうち、Dで割り切れるものの個数はCountB_D = B//D
B以下の整数のうち、CでもDでも割り切れるものの個数はCountB_CD = B//lcm(C,D)

CountB = B - (CountB_C + CountB_D - CountB_CD)

"""
from fractions import gcd

def solve():
    A, B, C, D = list(map(int, input().split()))
    def lcm(a, b):
        """ aとbの最小公倍数を返す """
        return a*b // gcd(a, b)

    def f(x):
        """ 1以上x以下の整数のうち、CでもDでも割り切れないものの個数を返す """
        return x - (x//C + x//D - x//lcm(C,D))    

    ans = f(B) - f(A)

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
import fractions
E=(C * D) //fractions.gcd(C, D)
print(E)
c=1/C
d=1/D
e=1/E
C_min=int(A*c)+1
C_max=int(B*c)
D_min=int(A*d)+1
D_max=int(B*d)

CD_min=int(A*e)+1
CD_max=int(B*e)+1
    
print([C_min,C_max,D_min,D_max,CD_min,CD_max])
M=C_max-C_min+D_max-D_min-(CD_max-CD_min)
print(B-A-1-M)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
X = max(C,D)
Y = min(C,D)
def gcd(a,b):
  while b!= 0:
    a,b = b,a%b
  return a
l = C*D/ gcd(X,Y)
def f(x):
  return x - (x//C + x//D - x//l)
ans = f(B) - f(A-1)
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
X = max(C,D)
Y = min(C,D)
def gcd(a,b):
  while b!= 0:
    a,b = b,a%b
  return a
l = C*D/ gcd(X,Y)
def f(x):
  return x - (x//C + x//D - x//l)
ans = f(B) - f(A-1)
print(int(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-
"""解説
B以下の整数のうち、CでもDでも割り切れないものの個数をCountBとする
A以下の整数のうち、CでもDでも割り切れないものの個数をCountAとする

求める答えは、CountB - CountA

・CountBの求め方
B以下の整数のうち、Cで割り切れるものの個数はCountB_C = floor(B/C)
B以下の整数のうち、Dで割り切れるものの個数はCountB_D = floor(B/D)
B以下の整数のうち、CでもDでも割り切れるものの個数はCountB_CD = floor(B/lcm(C,D))

CountB = B - (CountB_C + CountB_D - CountB_CD)

"""
from fractions import gcd
from math import floor

def solve():
    A, B, C, D = list(map(int, input().split()))
    A -= 1
    def lcm(a, b):
        """ aとbの最小公倍数を返す """
        return a*b // gcd(a, b)
    
    CountB = B - (floor(B/C) + floor(B/D) - floor(B/lcm(C,D)))
    CountA = A - (floor(A/C) + floor(A/D) - floor(A/lcm(C,D)))
    ans = CountB - CountA

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a,b,c,d=map(int, input().split())
tisai = (c*d/gcd(c,d))
n=[c,d]
count=0
for k in range(2):
    count += ((b//n[k])-((a-1)//n[k]))
count -= ((b//tisai)-((a-1)//tisai))
print(int((b-a+1)-count))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int,input().split())
li = [i for i in range(a, b+1)]
print(li)
cf = [True if i%c != 0 else False for i in li]
print(cf)
df = [True if i%d != 0 else False for i in li]
print(df)
n = 0
for i in range(len(cf)):
    if cf[i] and df[i]:
        n+=1
print(n)

Submission status: Wrong Answer

Solution code:
def lcm(a, b):
    if b > a:
        a, b = b, a

    x = a * b
    r = b % a
    while r != 0:
        a = b
        b = r
        r = b % a

    return x // b


A, B, C, D = map(int, input().split())
CD = lcm(D, C)
A -= 1

n = (B // C) + (B // D) - (B // CD)
n -= (A // C) + (A // D) - (A // CD)
print(B - A - n)

Submission status: Wrong Answer

Solution code:
def lcm(a, b):
    if b > a:
        a, b = b, a

    x = a * b
    r = b % a
    while r != 0:
        a = b
        b = r
        r = b % a

    return x / b


A, B, C, D = map(int, input().split())
CD = lcm(D, C)
A -= 1

n = (B // C) + (B // D) - (B // CD)
n -= (A // C) + (A // D) - (A // CD)
print(B - A - n)

Submission status: Wrong Answer

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

# 最大公約数。Euclidの互除法. c<dとする。
def gcd(x, y):
  if y == 0:
    return x
  else:
    return gcd(y, x%y)

# 最小公倍数
l = c*d/gcd(c,d)

def lowX(x,c,d,l):
  ans = x - x//c - x//d + x//l
  return ans
lowB = lowX(b,c,d,l)
lowA = lowX(a-1,c,d,l)
print(int(lowB-lowA))

Submission status: Wrong Answer

Solution code:
from sys import stdin




def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)



a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d

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

LCM_num = int(b//(LCM)-(a-1)//(LCM))

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

Submission status: Wrong Answer

Solution code:
from sys import stdin




def gcd(n,m):
    if n<m:
        return gcd(m,n)
    if n%m==0:
        return m
    else:
        return gcd(m,n%m)



a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d

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

LCM_num = int(b//(LCM)-(a-1)//(LCM))

print(b-a+1-(c_num + d_num - LCM_num))

Submission status: Wrong Answer

Solution code:
from sys import stdin
from fractions import gcd
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d

GCD = gcd(c,d_num)

LCM = d*c/GCD
cd_num = int(b//(LCM)-(a-1)//(LCM))

print(b-a+1-(c_num + d_num - cd_num))

Submission status: Wrong Answer

Solution code:
from sys import stdin
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d
if c_num>d_num:
    big_one = c
    small_one = d
else:
    big_one = d
    small_one = c
while True:
    amari = big_one%small_one
    if(amari==0):
        GCD = small_one
        break
    else:
        big_one = small_one
        small_one = amari
LCM = d*c/GCD
cd_num = int(b//(LCM)-(a-1)//(LCM))
print(b-a+1-(c_num + d_num - cd_num))

Submission status: Wrong Answer

Solution code:
from sys import stdin

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d

if c_num>d_num:
    big_one = c
    small_one = d
else:
    big_one = d
    small_one = c


while True:
    amari = big_one%small_one
    if(amari==0):
        GCD = small_one
        break
    else:
        big_one = small_one
        small_one = amari

LCM = d*c/GCD



cd_num = int(b//(LCM)-(a-1)//(LCM))


print(b-a+1-(c_num + d_num - cd_num))

Submission status: Wrong Answer

Solution code:
from sys import stdin

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

c_num = b//c-(a-1)//c
d_num = b//d-(a-1)//d

if c_num>d_num:
    big_one = c
    small_one = d
else:
    big_one = d
    small_one = c


while True:
    amari = big_one%small_one
    if(amari==0):
        GCD = small_one
        break
    else:
        big_one = small_one
        small_one = amari

LCM = d*c/GCD



cd_num = int(b//(LCM)-(a-1)//(LCM))


print(b-a+1-(c_num + d_num - cd_num))



"""
count = 0
for i in range(a,b+1):
    print(i)
    if(i%c==0 or i%d==0):
        count +=1
"""
"""
aaa = set()
i = 1
count=0
while(True):
    
    if(a//c<= c//i <=b//c):
        print(c//i)
        count += 1
    elif(c//i<=a//c):
        break
    i += 1


i = 1
while(True):
    
    if(a//d<= d//i <=b//d):
        print(d//i)
        count += 1
    elif(d//i<=a//d):
        break
    i += 1

if(a//d<a//c):
    min = a//d
else:
    min = a//c

if(b//c<b//d):
    max = b//d
else:
    max = b//c


print(count)
print(b-a+1-(count))

while(True):
    
    if(min<= d*c//i <=max):
        print(d//i)
        count -= 1
    elif(d*c//i<=min):
        break
    i += 1


print(count)
print(b-a+1-(count))
"""

Submission status: Wrong Answer

Solution code:
#整数 A,B,C,D が与えられます。
#A 以上 B 以下の整数のうち、C でも Dでも割り切れないものの個数を求めてください。

def calc_devided_number_by(A,B,N):
    if A%N==0:
        can_devide_number=int(B/N)-int(A/N)+1
    else:
        can_devide_number=int(B/N)-int(A/N)
    return can_devide_number

import fractions

A,B,C,D = list(map(int, input().split()))
#print(A,B,C,D)
#print("A～Bの個数",B-A+1)
all_number=B-A+1
#print("Cで割れる数",calc_devided_number_by(A,B,C))
can_devide_by_C=calc_devided_number_by(A,B,C)
#print("Dで割れる数",calc_devided_number_by(A,B,D))
calc_can_devide_by_D=calc_devided_number_by(A,B,D)
#print("CでもDでも割れる数",calc_devided_number_by(A,B,C*D/fractions.gcd(C,D)))
calc_can_devide_by_C_and_D=calc_devided_number_by(A,B,C*D/fractions.gcd(C,D))

ans=all_number-can_devide_by_C-calc_can_devide_by_D+calc_can_devide_by_C_and_D
#print("ans",end="")
print(ans)