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 = list(map(int, input().split())) 

#A, Bの公約数 (gcd(C,D)), 公倍数
try:
    from math import gcd
except:
    from fractions import gcd
    
LCM = C * D / gcd(C,D)
    
# B以下でCでもDでも割り切れない数
Ans_B = B - (B//C + B//D - B//LCM)
# A未満でCでもDでも割り切れない数
Ans_A = A-1 - ((A-1)//C + (A-1)//D  - (A-1)//LCM) 
    
print(int(Ans_B - Ans_A))

Submission status: Wrong Answer

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

#A, Bの公約数 (gcd(C,D)), 公倍数
from fractions import gcd
LCM = C * D / gcd(C,D)
    

# B以下でCでもDでも割り切れない数
Ans_B = B - (B//C + B//D - B//LCM)
# A未満でCでもDでも割り切れない数
Ans_A = A-1 - ((A-1)//C + (A-1)//D  - (A-1)//LCM) 
    
print(Ans_B - Ans_A)

Submission status: Wrong Answer

Solution code:
import math
#from decimal import Decimal
a, b, c, d = map(float, input().split())

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

def count(a, c, d):
    tmp_a= a - math.floor(a/c) - math.floor(a/d)
    tmp_a += math.floor(a/((c*d)/gcd(c, d)))
    return tmp_a

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

Submission status: Wrong Answer

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

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

def count(a, c, d):
    tmp_a= a - math.floor(a/c) - math.floor(a/d)
    tmp_a += math.floor(a/((c*d)/gcd(c, d)))
    return tmp_a

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

Submission status: Wrong Answer

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

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

def count(a, c, d):
    tmp_a= a - math.floor(a/c) - math.floor(a/d)
    tmp_a += math.floor(a/math.floor((c*d)/gcd(c, d)))
    return tmp_a

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

Submission status: Wrong Answer

Solution code:
import math

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

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

def count(a, c, d):
    tmp_a= a - math.floor(a/c) - math.floor(a/d)
    tmp_a += math.floor(a/math.floor(c*d/gcd(c, d)))
    return tmp_a

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

Submission status: Wrong Answer

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

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

tmp_b= b - math.floor(b/c) - math.floor(b/d)
tmp_b += math.floor(b/math.floor(c*d/gcd(c, d)))

tmp_a= (a-1) - math.floor((a-1)/c) - math.floor((a-1)/d)
tmp_a += math.floor((a-1)/math.floor(c*d/gcd(c, d)))

print(tmp_b-tmp_a)

Submission status: Wrong Answer

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

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

tmp_b= b - math.floor(b/c) - math.floor(b/d)
tmp_b += math.floor(b/math.floor(c*d/gcd(c, d)))

tmp_a= a - math.floor(a/c) - math.floor(a/d)
tmp_a += math.floor(a/math.floor(c*d/gcd(c, d)))

print(tmp_b-tmp_a+1)

Submission status: Wrong Answer

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

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

tmp_b= b - math.floor(b/c) - math.floor(b/d)
tmp_b += math.floor(b/(c*d/gcd(c, d)))

tmp_a= a - math.floor(a/c) - math.floor(a/d)
tmp_a += math.floor(a/(c*d/gcd(c, d)))

print(tmp_b-tmp_a+1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

#A-Bの範囲でXで割り切れる数
def Num_Div(A, B ,X):
    if B-A >= X:
        ans=(B-A)//X
    else:
        ans=0
        for i in range(A, B+1):
            if i%X==0:
                ans=1
                break
    return ans       

#A, Bの公約数
def GCD(a, b):     
    if  a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

LCM = C * D / GCD(C,D)
    
ans_C = Num_Div(A,B,C)
ans_D = Num_Div(A,B,D)         
ans_CD = Num_Div(A,B,LCM)            
   
print(B - A - ans_C - ans_D + ans_CD)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int, input().split())
 
#cとdの最大公約数を求める
first = [c,d%c]
first.sort()
if d%c==0:
  cd = c
elif first[0]==1:
  cd = 1
else:
  while first[0]>=2:
    first[1] = first[1]%first[0]
    first.sort()
    if first[0]==0:
      cd = first[1]
    elif first[0]==1:
      cd = 1
lcm = c*d/cd
 
#1.7＊10^17みたいなノリだから、intにするとまずいのでは
zen = b-a+1
if a%c==0:
  c_num = b//c - a//c + 1
else:
  c_num = b//c - a//c
  
if a%d==0:
  d_num = b//d - a//d + 1
else:
  d_num = b//d - a//d
  
if a%lcm==0:
  lcm_num = int(b//lcm - a//lcm + 1)
else:
  lcm_num = int(b//lcm - a//lcm)

ans = zen - c_num - d_num + lcm_num
print(ans)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int, input().split())
 
#cとdの最大公約数を求める
first = [c,d%c]
first.sort()
if d%c==0:
  cd = c
elif first[0]==1:
  cd = 1
else:
  while first[0]>=2:
    first[1] = first[1]%first[0]
    first.sort()
    if first[0]==0:
      cd = first[1]
    elif first[0]==1:
      cd = 1
lcm = c*d/cd
 
#1.7＊10^17みたいなノリだから、intにするとまずいのでは
zen = b-a+1
c_num = (b//c) - int(math.ceil(a/c))+1
d_num = (b//d) -int(math.ceil(a/d))+1
lcm_num = int(b//lcm) - int(math.ceil(a/lcm))+1
ans = zen - c_num - d_num + lcm_num
print(ans)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int, input().split())
 
#cとdの最大公約数を求める
first = [c,d%c]
first.sort()
if d%c==0:
  cd = c
elif first[0]==1:
  cd = 1
else:
  while first[0]>=2:
    first[1] = first[1]%first[0]
    first.sort()
    if first[0]==0:
      cd = first[1]
    elif first[0]==1:
      cd = 1
lcm = c*d/cd

#1.7＊10^17みたいなノリだから、intにするとまずいのでは
zen = b-a+1
c_num = (b//c) -math.ceil(a/c)+1
d_num = (b//d) -math.ceil(a/d)+1
lcm_num = (b//lcm) - math.ceil(a/lcm)+1
ans = zen - int(c_num) - int(d_num) + int(lcm_num)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int, input().split())
 
#cとdの最大公約数を求める
first = [c,d%c]
first.sort()
if d%c==0:
  cd = c
elif first[0]==1:
  cd = 1
else:
  while first[0]>=2:
    first[1] = first[1]%first[0]
    first.sort()
    if first[0]==0:
      cd = first[1]
    elif first[0]==1:
      cd = 1
lcm = c*d/cd
      
zen = b-a+1
c_num = (b//c) -math.ceil(a/c)+1
d_num = (b//d) -math.ceil(a/d)+1
lcm_num = (b//lcm) - math.ceil(a/lcm)+1
ans = zen - c_num - d_num + lcm_num
print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int, input().split())
 
#cとdの最大公約数を求める
first = [c,d%c]
first.sort()
if d%c==0:
  cd = c
elif first[0]==1:
  cd = 1
else:
  while first[0]>=2:
    first[1] = first[1]%first[0]
    first.sort()
    if first[0]==0:
      cd = first[1]
    elif first[0]==1:
      cd = 1
lcm = c*d/cd
      
zen = b-a+1
c_num = (b//c)-math.ceil(a/c)+1
d_num = (b//d)-math.ceil(a/d)+1
lcm_num = (b//lcm)-math.ceil(a/lcm)+1
ans = zen-c_num-d_num+lcm_num
print(ans)

Submission status: Wrong Answer

Solution code:
#######################################
import numpy as np
import math
import copy
import re
import sys
#sys.exit(0)

inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))

#or
#print(" ".join(list(map(str, lis))))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def lcm(a, b): #最小公倍数
  return int(a * b // gcd (a, b))

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): #最小公倍数(3over)
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

#processing stock
"""
a = sorted(a)
a = sorted(a, reverse=True)

"""

#regex
"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   # 1回目: ca      2回目: ca   
    print res.start()   # 1回目: 0       2回目: 6      
    print res.end()     # 1回目: 2       2回目: 8      
    print res.span()    # 1回目: (0, 2)  2回目: (6, 8)
"""


#math
"""
#切り捨て
math.floor()
# 切り上げ
math.ceil()
"""

#input stock
"""
n = int(input())

#list
a = list(map(int, input().split()))
a,b = map(int, input().split())

d=[]
for i in range(n):
  d[i]=int(input())

#2dim-list
a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""

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

def anti_d(num):
  return num - (int(num/c) + int(num/d) - int(num/lcm(c,d)))

ret = anti_d(b) - anti_d(a-1)
print(ret)

Submission status: Wrong Answer

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

#cとdの最大公約数を求める
first = [c,d%c]
first.sort()
if d%c==0:
  cd = c
elif first[0]==1:
  cd = 1
else:
  while first[0]>=2:
    first[1] = first[1]%first[0]
    first.sort()
    if first[0]==0:
      cd = first[1]
    elif first[0]==1:
      cd = 1
      
zen = b-a+1
c_num = b//c -math.ceil(a/c)+1
d_num = b//d -math.ceil(a/d)+1
lcm_num = b//(c*d/cd) - math.ceil(a/(c*d/cd))+1
ans = zen - c_num - d_num + lcm_num
print(ans)

Submission status: Wrong Answer

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

N = B - A
count = 0
for i in range(N):
    if (A + i) % C == 0 or (A + i) % D == 0:
        continue
    else:
        count += 1

print(count)

Submission status: Wrong Answer

Solution code:
import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

def GCD(x, y):
    return x if y == 0 else GCD(y, x % y)


def LCM(x, y):
    return x // GCD(x, y) * y

num = getInputListInt()

a = num[0]
b = num[1]
c = num[2]
d = num[3]

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

cd = LCM(c, d)

cd_modzero = math.floor(b/cd) - math.floor((a-1)/cd)

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

num = getInputListInt()

a = num[0]
b = num[1]
c = num[2]
d = num[3]

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

cd = c / fractions.gcd(c, d) *d

cd_modzero = math.floor(b/cd) - math.floor((a-1)/cd)

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import copy
import fractions
import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

num = getInputListInt()

a = num[0]
b = num[1]
c = num[2]
d = num[3]

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

cd = c * d / fractions.gcd(c, d)

cd_modzero = math.floor(b/cd) - math.floor((a-1)/cd)

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math
import copy
from fractions import gcd
# import numpy as np

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

num = getInputListInt()

a = num[0]
b = num[1]
c = num[2]
d = num[3]

c_modzero = math.floor(b/c) - math.floor((a-1)/c)
d_modzero = math.floor(b/d) - math.floor((a-1)/d)

cd = math.floor(c*d/ gcd(c, d))

cd_modzero = math.floor(b/(cd)) - math.floor((a-1)/(cd))

ans = b - a + 1 - (c_modzero + d_modzero - cd_modzero)

print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
i, j = c, d
while i != j:
    if i > j:
        i = i - j
    else:
        j = j - i
gcd = i
lcm = c*d/gcd

def cont(x):
    cnt1 = x//c 
    cnt2 = x//d 
    ans = x - cnt1 - cnt2 + x//lcm
    return int(ans)

print(cont(b) - cont(a-1))

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)

S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

E = int(lcm(C,D))

X = int((B//C))-int((A//C))
Y = int((B//D))-int((A//D))
Z = int((B//(E)))-int((A//(E)))

print(int(B-A-X-Y+Z))

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)

S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

E = lcm(C,D)

X = int((B//C))-int((A//C))
Y = int((B//D))-int((A//D))
Z = int((B//(E)))-int((A//(E)))

print(int(B-A-X-Y+Z))

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)

S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

E = lcm(C,D)

X = int(B/C)-int((A-1)/C)
Y = int(B/D)-int((A-1)/D)
Z = int(B/E)-int((A-1)/E)

print(B-A+1-X-Y+Z)

Submission status: Wrong Answer

Solution code:

S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

X = (B/C)-(A/C)
Y = (B/D)-(A/D)
Z = (B/(C*D))-(A/(C*D))

print(int(B-A+1-X-Y+Z))

Submission status: Wrong Answer

Solution code:

S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

X = int((B//C))-int((A//C))
Y = int((B//D))-int((A//D))
Z = int((B//(C*D)))-int((A//(C*D)))

print(int(B-A-X-Y+Z))

Submission status: Wrong Answer

Solution code:
S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

X = int((B//C)-(A//C))
Y = int((B//D)-(A//D))
Z = int((B//(C*D))-(A//(C*D)))+1

print(int(B-A-X-Y+Z))

Submission status: Wrong Answer

Solution code:
S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

X = int((B//C)-(A//C))
Y = int((B//D)-(A//D))
Z = int((B//(C*D))-(A//(C*D)))

print(int(B-A-X-Y+Z))

Submission status: Wrong Answer

Solution code:
S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

X = (B/C)-(A/C)
Y = (B/D)-(A/D)
Z = (B/(C*D))-(A/(C*D))

print(int(B-A-X-Y+Z))

Submission status: Wrong Answer

Solution code:
import sys
import collections
import copy

S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

X = (B//C)-(A//C)
Y = (B//D)-(A//D)
Z = (B//(C*D))-(A//(C*D))

print(B-A-X-Y+Z)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a

    if b == 0:
        return a

    else:
        return gcd(b, a % b)

A, B, C, D = map(int, input().split())
lcm = C * D // gcd(C, D)
tmp = (B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // lcm - A // lcm)
output = B - A + 1 - tmp

print(output)

Submission status: Wrong Answer

Solution code:
import fractions

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

cde = b // c - a // c
dde = b // d - a // d
lde = b // lcm - a // lcm

print(b - a + 1 - cde - dde + lde)

Submission status: Wrong Answer

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

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

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

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

def count(x):
    return B // x - ((A - 1) // x)

s = count(C)
t = count(D)
u = count(lcm)
v = count(1)

print(v - s - t + u)

Submission status: Wrong Answer

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

if C != D:
    C = min(C, D)
    D = max(C, D)
else:
    C = C
    D = D

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

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

s = B // C - (A - 1) // C
t = B // D - (A - 1) // D
u = B // lcm - (A - 1) // lcm

print(B - A + 1 - s - t + u)

Submission status: Wrong Answer

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

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

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

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

s = B // C - (A - 1) // C
t = B // D - (A - 1) // D
u = B // lcm - (A - 1) // lcm

print(B - A + 1 - s - t + u)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d = map(int,input().split())
cd = (c*d) 
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)
 
result = b-a+1 -(c_sum+d_sum-cd_sum)
print((result))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
cd = c*d
c_sum = (b // c) - ((a-1) // c)
d_sum = (b // d) - ((a-1) // d)
cd_sum = (b // cd) - ((a-1) // cd)

result = b-a+1 -(c_sum+d_sum-cd_sum)
print(result)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
cd = c*d
c_start = min(b,a + (a % c))
d_start = min(b,a + (a % d))
cd_start = min(b,a + (a % cd))
c_sum = (b-c_start) // c + 1
d_sum = (b-d_start) // d + 1
cd_sum = (b-cd_start) // cd + 1 
result = b-a+1 -(c_sum+d_sum-cd_sum)
print(result)

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = map(int, input().split())
count = 0
cd = c * d
target = b - a + 1
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
def lcm(x, y):
    return (x * y) // gcd(x, y)
if (c == 0) or (d == 0):
  print(0)
  sys.exit()
  
if target % c == 0:
    count += int(target // c)
else:
    count += int(target // c) + 1
if target % d == 0:
    count += int(target // d)
else:
    count += int(target // d) + 1
    
tmp_cou = 0
min_lcm = lcm(c, d)
if target % min_lcm == 0:
    tmp_cou += int(target // min_lcm)
else:
    tmp_cou += int(target // min_lcm) + 1
count -= tmp_cou
print(target - count)

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = map(int, input().split())
count = 0
cd = c * d
target = b - a + 1
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
def lcm(x, y):
    return (x * y) // gcd(x, y)
if (c == 0) or (d == 0):
  print(0)
  sys.exit()

if (a % c == 0) and (b % c == 0):
  count += int(target // c) + 1
elif target % c == 0:
  count += int(target // c)
else:
  count += int(target // c) + 1
if (a % d == 0) and (b % d == 0):
  count += int(target // d) + 1
if target % d == 0:
    count += int(target // d)
else:
    count += int(target // d) + 1
    
tmp_cou = 0
min_lcm = lcm(c, d)
if target % min_lcm == 0:
    tmp_cou += int(target // min_lcm)
else:
    tmp_cou += int(target // min_lcm) + 1
count -= tmp_cou
print(target - count)

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = map(int, input().split())
count = 0
cd = c * d
target = b - a + 1
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
def lcm(x, y):
    return (x * y) // gcd(x, y)
if (a % c == 0) and (b % c == 0):
  count += int(target // c) + 1
elif target % c == 0:
  count += int(target // c)
else:
  count += int(target // c) + 1
if (a % d == 0) and (b % d == 0):
  count += int(target // d) + 1
if target % d == 0:
    count += int(target // d)
else:
    count += int(target // d) + 1
    
tmp_cou = 0
min_lcm = lcm(c, d)
if target % min_lcm == 0:
    tmp_cou += int(target // min_lcm)
else:
    tmp_cou += int(target // min_lcm) + 1
count -= tmp_cou
print(target - count)

Submission status: Wrong Answer

Solution code:
import math
a, b, c, d = map(int, input().split())
count = 0
cd = c * d
target = b - a + 1
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x
def lcm(x, y):
    return (x * y) // gcd(x, y)
  
if target % c == 0:
    count += int(target // c)
else:
    count += int(target // c) + 1
if target % d == 0:
    count += int(target // d)
else:
    count += int(target // d) + 1
    
tmp_cou = 0
min_lcm = lcm(c, d)
if target % min_lcm == 0:
    tmp_cou += int(target // min_lcm)
else:
    tmp_cou += int(target // min_lcm) + 1
count -= tmp_cou
print(target - count)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
count = 0
ab = a * b
target = b - a + 1
if (a % c == 0 or b % c == 0) or (a % d == 0 or b % d == 0):
  count += int(target // c) + 1
  count += int(target // d) + 1
  tmp_cou = 0
  while d <= c:
    d = d / ab
    tmp_cou += 1
  count -= tmp_cou
else:
  count += int(target // c)
  count += int(target // d)
  tmp_cou = 0
  while d <= c:
    d = d / ab
    tmp_cou += 1
  count -= tmp_cou
print(target - count)

Submission status: Wrong Answer

Solution code:
import fractions as fc

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

def lcm(C,D):
  return C*D / fc.gcd(C,D)
CD=lcm(C,D)

print(int(B-A+1-((B//C + B//D - B//CD) - ((A-1)//C + (A-1)//D - (A-1)//CD))))

Submission status: Wrong Answer

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

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

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

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

if A % C != 0:
    a = A // C + 1
else:
    a = A // C

b = B // C

if A % D !=0:
    c = A // D + 1
else:
    c = A // D
    
d = B // D

if A % lcm != 0:
    e = A // lcm + 1
else:
    e = A // lcm
    
f = B // lcm

single_c, single_d, double = 0, 0, 0

if a <= b:
    single_c = b - a + 1
else:
    single_c = 0

if c <= d:
    single_d = d - c + 1
else:
    single_d = 0

if e <= f:
    double = f - e + 1
else:
    double = 0

print(B - A + 1 - single_c - single_d + double)

Submission status: Wrong Answer

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

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

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

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

a = A // C + 1
b = B // C
c = A // D + 1
d = B // D
e = A // lcm + 1
f = B // lcm

single_c, single_d, double = 0, 0, 0

if a <= b:
    single_c = b - a + 1
else:
    single_c = 0

if c <= d:
    single_d = d - c + 1
else:
    single_d = 0

if e <= f:
    double = f - e + 1
else:
    double = 0

print(B - A + 1 - single_c - single_d + double)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
a_c = (a-1)//c
b_c = b//c
a_d = (a-1)//d
b_d = b//d
a_cd = (a-1)//(c*d)
b_cd = b//(c*d)
ans = (b-a+1) - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D=map(int, input().split())
x=C*D/fractions.gcd(C, D)
p=B//C-(A-1)//C
q=B//D-(A-1)//D
r=B//x-(A-1)//x
print(int(B-(A-1)-(p+q-r)))

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:
a,b,c,d = map(int,input().split())
def gcd(x,y):
    while y:
        x, y = y, x%y
    return x
cd = int(c*d/gcd(c,d))
l = [c,d,cd]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    e = a+l[i]-a%l[i]
    if e < b:
      if i < 2:
        count += (1+len(range(e+1,b+1))//l[i])
      else:
        count -= (1+len(range(e+1,b+1))//l[i])
    
print(len(range(a,b+1))-count)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
def gcd(x,y):
    while y:
        x, y = y, x%y
    return x
cd = int(c*d/gcd(c,d))
l = [c,d,cd]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    e = a+l[i]-a%l[i]
    if e+1 < b:
      if i < 2:
        count += (1+len(range(e+1,b+1))//l[i])
      else:
        count -= (1+len(range(e+1,b+1))//l[i])
    
print(len(range(a,b+1))-count)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
l = [c,d,c*d]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    e = a+l[i]-a%l[i]
    if e+1 < b:
      if i < 2:
        count += (1+len(range(e+1,b+1))//l[i])
      else:
        count -= (1+len(range(e+1,b+1))//l[i])
    
print(len(range(a,b+1))-count)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
l = [c,d,c*d]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    e = a+l[i]-a%l[i]+1
    if e < b:
      if i < 2:
        count += (1+len(range(e,b+1))//l[i])
      else:
        count -= (1+len(range(e,b+1))//l[i])
print(len(range(a,b+1))-count)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
l = [c,d,c*d]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    if i < 2:
      count += (1+len(range(a+l[i]-a%l[i]+1,b+1))//l[i])
    else:
      count -= (len(range(a+l[i]-a%l[i]+1,b+1))//l[i])
print(len(range(a,b+1))-count)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
l = [c,d,c*d]
count = 0
for i in range(3):
  if a%l[i] == 0:
    if i < 2:
      count += (1+len(range(a+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+1,b+1))//l[i])
  else:
    if i < 2:
      count += (1+len(range(a+l[i]-a%l[i]+1,b+1))//l[i])
    else:
      count -= (1+len(range(a+l[i]-a%l[i]+1,b+1))//l[i])
print(len(range(a,b+1))-count)

Submission status: Wrong Answer

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

def divide (x):
    p = x // c
    q = x // d
    r = x // lcm_ab
    return p,q,r

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

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

lcm_ab = lcm(a,b)
ac,ad,la = divide(a)
bc,bd,lb = divide(b)

ans = (b-a)-(bc-ac)-(bd-ad)+(lb-la)+1
print(ans)

Submission status: Wrong Answer

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

def divide (x):
    p = x // c
    q = x // d
    r = x // lcm_ab
    return p,q,r

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

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

lcm_ab = lcm(a,b)
ac,ad,la = divide(a)
bc,bd,lb = divide(b)
ans = (b-a)-(bc-ac)-(bd-ad)+(lb-la)+1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
m=0
e = c * d
num_c = int((b-a+1)/c)
num_d = int((b-a+1)/d)
num_e = int((b-a+1)/e)
m = num_c + num_d - num_e
print(b-a+1-m)

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 ans(x):
    return x - (x // C + x // D - x // (C * D / gcd(C, D)))

print(ans(B) - ans(A - 1))

Submission status: Wrong Answer

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

def ans(x):
    if C != D:
        return x - (x // C + x // D - x // (C * D))
    else:
        return x - x // C

print(ans(B) - ans(A - 1))

Submission status: Wrong Answer

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

def ans(x):
    return x - (x // C + x // D - x // (C * D))

print(ans(B) - ans(A - 1))