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: Runtime Error

Solution code:


import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # １行に複数の数値(m個)かつ、n行続く場合（出力は二次元リスト：[['1', '2'], ['4', '5']]）

# dとAの行が交互に並んでいる場合
s = sys.stdin.readlines()
n, k=map(int, s[0].split())
d=[]
A=[]
for i in s[1:2*k:2]:
    d.append(int(i))
for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))
"""

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

import math
f = math.gcd(a,b) # 最大公約数
f2 = a*b // f # 最小公倍数

# b以下で条件を満たす個数
shou1=b//c
shou2=b//d
shou3=b//f2
num_b=b-(shou1+shou2-shou3)

# a-1以下で条件を満たす個数
shou4=(a-1)//c
shou5=(a-1)//d
shou6=(a-1)//f2
num_a=(a-1)-(shou4+shou5-shou6)

print(num_b-num_a)

Submission status: Runtime Error

Solution code:
import math

a,b,c,d=map(int,input().split())
C=b//c-((a-1)//c)
D=b//d-((a-1)//d)
g=math.gcd(c,d)
l=c*d/g
E=b//l-((a-1)//l)
print(int(b-a+1-C-D+E))

Submission status: Runtime Error

Solution code:
import fractinos

a,b,c,d=map(int,input().split())
C=b//c-((a-1)//c)
D=b//d-((a-1)//d)
g=fractions.gcd(c,d)
E=b//g-((a-1)//g)
print(b-a+1-C-D+E)

Submission status: Runtime Error

Solution code:
import math

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

b_c = b//c - (a-1)//c
d_c = b//d - (a-1)//d
cd = (c * d) // math.gcd(c, d)
cd_c = b//cd - (a-1)//cd

print((b - a + 1) - (b_c + d_c - cd_c))

Submission status: Runtime Error

Solution code:
import math

def main():
    A,B,C,D = map(int, input().split())  
    lc = lcm(C, D)
    Bsum = B - (B//C) - (B//D) + (B//lc)
    A1 = A-1
    Asum = A1 - (A1//C) - (A1//D) + (A1//lc)
    print(Bsum-Asum)
    
def lcm(x, y):
    return (x * y) // math.gcd(x, y)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import fractions
A, B, C, D = [int(s) for s in input().split()]


def countDiv(x, C, D):
    c = x // C
    d = x // D
    cd = x // fractions.gcd(c, d)
    return(x - c - d + cd)


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

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = [int(s) for s in input().split()]


def countDiv(x, C, D):
    c = x // C
    d = x // D
    cd = x // math.gcd(c, d)
    return(x - c - d + cd)


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

Submission status: Runtime Error

Solution code:
import math


def lcm(x, y):  # 最小公倍数
    return (x * y) // math.gcd(x, y)


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


print(all - part)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from fractions import gcd

def ceil(a, b):
  return -(-a//b)

a, b, c, d = map(int, input().split())
if c == 1:
  print(0)
  sys.exit()
cd_lcm = c*d//gcd(c, d)
c_left, c_right = ceil(a,c), b//c
d_left, d_right = ceil(a,d), b//d
cd_left, cd_right = ceil(a,cd_lcm), b//(cd_lcm)
cv, dv, cdv = c_right - c_left + 1, d_right - d_left + 1, cd_right - cd_left + 1
print((b - a + 1) - (cv + dv - cdv))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
#c_d = math.floor(((c*d)//(math.gcd(c,d))))
c_d = (c*d)//(math.gcd(c,d))
#print((math.gcd(c,d)))
a_c = (a-1) // c
a_d = (a-1) // d
a_c_d = (a-1) // c_d
a_ans = (a-1) - a_c - a_d + a_c_d
#ans1 = (a_c + a_d - a_c_d)
#print(c_d)
b_c = b // c
b_d = b // d
b_c_d = b // c_d
b_ans = b - b_c - b_d + b_c_d
#ans2 = (b_c + b_d -b_c_d)
#print(ans2)
#print(math.floor((b-a+1)-(ans2-ans1)))
print(math.floor(b_ans-a_ans))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
minCg = math.ceil(A/C)
maxCg = math.floor(B/C)
minDg = math.ceil(A/D)
maxDg = math.floor(B/D)
gcd = math.gcd(C,D) 
CD = (C*D) // gcd
minCDg = math.ceil(A/(CD))
maxCDg = math.floor(B/(CD))
Cg = maxCg - minCg +1
Dg = maxDg - minDg +1
CDg = maxCDg - minCDg +1
Anti = (Cg+Dg-CDg)
print(B-A+1-Anti)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
minCg = math.ceil(A/C)
maxCg = math.floor(B/C)
minDg = math.ceil(A/D)
maxDg = math.floor(B/D)
gcd = math.gcd(C,D) #最大公約数の参照
CD = (C*D) // gcd#最小公倍数の作り方
minCDg = math.ceil(A/(CD))
maxCDg = math.floor(B/(CD))
Cg = maxCg - minCg +1
Dg = maxDg - minDg +1
CDg = maxCDg - minCDg +1
Anti = (Cg+Dg-CDg)
print(B-A+1-Anti)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
minCg = math.ceil(A/C)
maxCg = math.floor(B/C)
minDg = math.ceil(A/D)
maxDg = math.floor(B/D)
gcd = math.gcd(C,D) #最大公約数の参照
CD = (C*D) // gcd　#最小公倍数の作り方
minCDg = math.ceil(A/(CD))
maxCDg = math.floor(B/(CD))
Cg = maxCg - minCg +1
Dg = maxDg - minDg +1
CDg = maxCDg - minCDg +1
Anti = (Cg+Dg-CDg)
print(B-A+1-Anti)

Submission status: Runtime Error

Solution code:
import math

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

E = (C*D)//math.gcd(C,D)

B_count = B-((B//C)+(B//D)-(B//E))
A_count = (A-1)-(((A-1)//C)+((A-1)//D)-((A-1)//E))

print(B_count-A_count)

Submission status: Runtime Error

Solution code:
from math import ceil, floor, gcd

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

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

divC = floor(b/c)-ceil(a/c)
divD = floor(b/d)-ceil(a/d)
res = (b-a) - (divC+divD) + floor(b/lcm(c,d))

print(res-1)

Submission status: Runtime Error

Solution code:

import fractions
a,b,c,d = map(int,input().split())	
lcm = c * d // fractions.gcd(c, d)
#print(lcm)
def divisor(x):
	
	x_c = fractions.floor(x/c)
	x_d = fractions.floor(x/d)
	#print(x_c,x_d)
	x_lcm = fractions.floor(x/lcm)
	#print(x_c,x_d,x_lcm)
	return x-x_c-x_d+x_lcm
#print(divisor(b),divisor(a))
ans = divisor(b)-divisor(a-1)
print(ans)

Submission status: Runtime Error

Solution code:

import math
a,b,c,d = map(int,input().split())	
lcm = c * d // math.gcd(c, d)
#print(lcm)
def divisor(x):
	
	x_c = math.floor(x/c)
	x_d = math.floor(x/d)
	#print(x_c,x_d)
	x_lcm = math.floor(x/lcm)
	#print(x_c,x_d,x_lcm)
	return x-x_c-x_d+x_lcm
#print(divisor(b),divisor(a))
ans = divisor(b)-divisor(a-1)
print(ans)

Submission status: Runtime Error

Solution code:
import statistics
import math
a,b,c,d = map(int,input().split())	
lcm = c * d // math.gcd(c, d)
#print(lcm)
def divisor(x):
	
	x_c = math.floor(x/c)
	x_d = math.floor(x/d)
	#print(x_c,x_d)
	x_lcm = math.floor(x/lcm)
	#print(x_c,x_d,x_lcm)
	return x-x_c-x_d+x_lcm
#print(divisor(b),divisor(a))
ans = divisor(b)-divisor(a-1)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

print( (B - A + 1) - (f(C) + f(D) - f(lcm)) )

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import math

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

g = int(c * d / math.gcd(c, d))

b_c = b // c
b_d = b // d
b_g = b // g
a_c = (a-1) // c
a_d = (a-1) // d
a_g = (a-1) // g

ans = (b - b_c - b_d + b_g) - ((a-1) - a_c - a_d + a_g)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

g = int(c * d / math.gcd(c, d))

b_c = b // c
b_d = b // d
b_g = b // g
a_c = (a-1) // c
a_d = (a-1) // d
a_g = (a-1) // g

ans = (b - b_c - b_d + b_g) - ((a-1) - a_c - a_d + a_g)
print(ans)

Submission status: Runtime Error

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

#A-1
A1 = (a-1) - (a-1)//c -(a-1)b//d +c*d//(gcd(c,d))*(a-1)

#Bまで
B = b - b//c - b//d +c*d//(gcd(c,d)) *b

print(B-A1)

Submission status: Runtime Error

Solution code:
from fractions import gcd


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


A, B, C, D = map(int, input().split())
SUM = B - A + 1
c = (B // C - (A - 1) // C)
d = (B // D - (A - 1) // D)
cd = (B // lcm(C, D) - (A - 1) // lcm(C, D))
print(B - A + 1 - (B // C - (A - 1) // C + B // D - (A - 1) // D - cd)))

Submission status: Runtime Error

Solution code:
from math import gcd


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


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

Submission status: Runtime Error

Solution code:
import math

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

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

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

Submission status: Runtime Error

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

import numpy as np

from_1_a = (A-1)//C +(A-1)//D - (A-1)//np.lcm(C,D)
from_1_b = B//C + B//D - B//np.lcm(C,D)

baisu_c_or_d = from_1_b -from_1_a
among = B -A  +1


print(among - baisu_c_or_d)

Submission status: Runtime Error

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

import numpy as np

from_1_a = int((A-1)/C) +int((A-1)/D) - int((A-1)/np.lcm(C,D))
from_1_b = int(B/C) +int(B/D) - int(B/np.lcm(C,D))

baisu_c_or_d = from_1_b -from_1_a
among = B -A  +1

print(among - baisu_c_or_d)

Submission status: Runtime Error

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

import numpy as np

from_1_a = int((A-1)/C) +int((A-1)/D) - int((A-1)/np.lcm(C,D))
from_1_b = int(B/C) +int(B/D) - int(B/np.lcm(C,D))

baisu_c_or_d = from_1_b -from_1_a
among = B -A  +1

print(among - baisu_c_or_d)

Submission status: Runtime Error

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

amari_ac = a % c
amari_ad = a % d
if amari_ac == 0:
    c_min = a
else:
    c_min = a+c - amari_ac
if amari_ad == 0:
    d_min = a
else:
    d_min = a+d - amari_ad

amari_bc = b % c
amari_bd = b % d
c_max = b-amari_bc
d_max = b-amari_bd

c_count = (c_max-c_min)//c + 1
d_count = (d_max-c_min)//d + 1

lcm_cd = c*d // gcd(c, d)
amari_acd = a % lcm_cd
if amari_acd == 0:
    cd_min = a
else:
    cd_min = a+lcm_cd - amari_acd

amari_bcd = b % lcm_cd
cd_max = b - amari_bcd

cd_count = (cd_max-cd_min)//lcm_cd + 1

if cd_max < a or b < cd_max:
    cd_count = 0
if cd_min < a or cd_min > b:
    cd_count = 0

print(ans-c_count-d_count+cd_count)

Submission status: Runtime Error

Solution code:
A,B,C,D = map(int, input().split())
from math import gcd
cd = C*D//gcd(D,C)
f = lambda x: B//x - ((A-1)//x)
print(B - A + 1 - (f(C) + f(D) - f(cd)))

Submission status: Runtime Error

Solution code:
import math
# import itertools
# import statistics
# import numpy as np
#n = int(input())
a, b, c, d = list(map(int, input().split()))
#b = list(map(int, input().split()))
total = b-a+1
lcm = int((c*d)/math.gcd(c, d))

d1 = b//c - a//c
d2 = b//d - a//d
add = b//lcm - a//lcm
if a % c == 0:
    d1 += 1
if a % d == 0:
    d2 += 1

print(total-d1-d2+add)

Submission status: Runtime Error

Solution code:
from math import gcd, floor, ceil
def lcd(x, y):
    return x*y//gcd(x,y)
def C():
    a,b,c,d = list(map(int, input().split()))
    c_divide = b//c - (a-1)//c
    d_divide = b//d - (a-1)//d
    cd_lcd = lcd(c,d)
    lcd_divide = b//cd_lcd - (a-1)//cd_lcd
    print(b-a+1 - c_divide - d_divide + lcd_divide)
C()

Submission status: Runtime Error

Solution code:
# abc131_c.py
'''
M を C,D でそれぞれ割り切れるもの
N を CD の最小公倍数で割り切れるもの
とすると
(B - A + 1) - (M - N)
で求められるはず
'''
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

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

A,B,C,D = map(int,input().split())
r = (B - A + 1)
M = math.ceil(r/C) + math.ceil(r/D)
N = math.ceil(r/lcm(C,D))
print(r-M+N)

Submission status: Runtime Error

Solution code:

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
import math

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

A,B,C,D = map(int,input().split())
r = (B - A + 1)
M = math.ceil(r/C) + math.ceil(r/D)
N = math.ceil(r/lcm(C,D))
print(r-M+N)

Submission status: Runtime Error

Solution code:
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
from math import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

def myAnswer(A:int,B:int,C:int,D:int) -> int:
   divC = B//C - (A - 1)//C 
   divD = B//D - (A - 1)//D
   divCD = B//lcm(C,D) - (A - 1)//lcm(C,D) 
   # print(divC,divD,divCD)
   return (B - A + 1) - (divC + divD - divCD)

def modelAnswer():
   return
def main():
   A,B,C,D = map(int,input().split())
   print(myAnswer(A,B,C,D))

if __name__ == '__main__':
   main()

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
K = B-A+1
E = (C*D)//math.gcd(C,D)
c = B//C - (A-1)//C
d = B//D - (A-1)//D
e = B//E - (A-1)//E
print(K-c-d+e)

Submission status: Runtime Error

Solution code:
import math

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


t = b//c + b//d - b//(c*d//g)
l = (a - 1)//c + (a - 1)//d - (a - 1)//(c*d//g)
ans = b - (a - 1) - t + l

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

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

a = ((A-1)//C+(A-1)//D)-(A-1)//lcm
b = (B//C+B//D)-B//lcm

print((B-A+1)-(b-a))

Submission status: Runtime Error

Solution code:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-RemainderMinimization.py
#
import math
a, b, c, d = map(int, input().split())
cd_lcm = (c * d) // math.gcd(c, d)
ab_c = b//c - (a-1)//c
ab_d = b//d - (a-1)//d
ab_cd_both = b//cd_lcm - (a-1)//cd_lcm
ab_cd_either = ab_c + ab_d - ab_cd_both
ab_cd_neither = b-a+1 - ab_cd_either

print(ab_cd_neither)

Submission status: Runtime Error

Solution code:
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-RemainderMinimization.py
#
import math
a, b, c, d = map(int, input().split())
cd_lcm = (c * d) // math.gcd(c, d)
ab_c = b//c - (a-1)//c
ab_d = b//d - (a-1)//d
ab_cd_both = b//cd_lcm - (a-1)//cd_lcm
ab_cd_either = ab_c + ab_d - ab_cd_both
ab_cd_neither = b-a+1 - ab_cd_either
# print("cd_lcm ab_cd_either {} {}".format(cd_lcm, ab_cd_either))

print(ab_cd_neither)

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input())
e=a
t=0
while e<=b:
  if e%c!=0 or e%d!=0:
    t+=1
  e+=1
print(t)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

C_count = B // C - A // C
if A % C == 0:
    C_count += 1
D_count = B // D - A // D
if A % D == 0:
    D_count += 1
CD_count = B // lcm(C, D) - A // lcm(C, D)
if A % lcm(C, D) == 0:
    CD_count += 1
div_count = C_count + D_count - CD_count
ans = B - A + 1 - div_count
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
count=0
def cc(a,b,c):
    if a%c==0 or b%c==0:
        return (b-a)//c+1
    else:
        return (b-a)//c
print(b-a+2-cc(a,b,c)-cc(a,b,d)+cc(a,b,(a*b)//math.gcd(c,d)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop
from math import gcd

INF = float('inf')
NIL = - 1


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


A, B, C, D = map(int, input().split())
total = B - A + 1

if A % C != 0:
    c_count = (B // C) - (A // C)
else:
    c_count = (B // C) - (A // C) + 1

if A % D != 0:
    d_count = (B // D) - (A // D)
else:
    d_count = (B // D) - (A // D) + 1


lcm = lcm(C, D)
if A % lcm != 0:
    lcm_count = (B // lcm) - (A // lcm)
else:
    lcm_count = (B // lcm) - (A // lcm) + 1


print(total - c_count - d_count + lcm_count)

Submission status: Runtime Error

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

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

from math import ceilf
from fractions import gcd

def solve():
    a, b, c, d = MI()

    e = b // c
    f = ceil(a / c)
    c2 = e - f + 1
    g = b // d
    h = ceil(a / d)
    d2 = g - h + 1

    cd = lcm(c, d)
    cdr = b // cd
    cdl = ceil(a / cd)
    cd2 = cdr - cdl + 1
    # print(c2, d2, cd2)
    print(b - a + 1 - c2 - d2 + cd2)


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
from math import gcd
def func(n):
    return n - (n//C + n//D - n//(C*D//gcd(C, D)))
A, B, C, D = map(int, input().split())
print(func(B) - func(A-1))

Submission status: Runtime Error

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

#B以下の整数の個数
x = B - (B // C) - (B // D)
#C,Dの最大公約数を求める
l = math.gcd(C, D)
#C,Dの最小公倍数を求める
temp = C * D // l 
#C,Dで重複して引いた数を足し合わせる
x += (B // temp)

#同様にA - 1以下の整数のうちの個数も求める
a = A - 1
y = a - (a // C) - (a // D)
y += (a // temp)

ans = x - y
print(ans)

Submission status: Runtime Error

Solution code:
import math

a,b,c,d = map(int,input().split())
cd = math.gcd(c, d)
lcmcd = c*d//cd
ans = 0
for i in range(a,b+1):
  if i % lcmcd != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import math

a,b,c,d = map(int,input().split())
cd = math.gcd(c, d)
lcm(cd) = c*d//cd
ans = 0
for i in range(a,b+1):
  if i % lcm(cd) != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(int(a),int(b)+1,))
ans = 0
for i in range(len(l)):
  if l[i] % c != 0 and l[i] % d != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(a,b+1,1))
ans = 0
for i in range(len(l)):
  if l[i] % c != 0 and l[i] % d != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(a,b+1))
ans = 0

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(b))
ans = 0

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(b))
ans = 0
for i in range(len(l)):
  if l[i] % c != 0 and l[i] % d != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(a, b+1))
ans = 0
for i in range(len(l)):
  if l[i] % c != 0 and l[i] % d != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(a,b+1))
ans = 0
for i in range(len(l)):
  if l[i] % c != 0 and l[i] % d != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(a,b+1))
ans = 0
for i in range(len(l)):
  l[i] % c != 0 and l[i] % d != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c,d = map(int,input().split())
l = list(range(a,b+1))
ans = 0
for i in l:
  l[i] % c != 0 and l[i] % d != 0:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
S = list(input())
count = 0
ans = [0]*(len(S))
for i in range(len(S)):
    if S[i] == "R":
        count += 1
    else:
        if count % 2 == 0:
            ans[i] += count//2
            ans[i-1] += count//2
            count = 0
        else:
            ans[i] += count//2 + 1
            ans[i-1] += count//2
            count = 0
	
S.reverse()
	
for i in range(len(S)):
    if S[i] == "L":
        count += 1
    else:
        if count % 2 == 0:
            ans[len(S)-i] += count//2
            ans[len(S)-i-1] += count//2
            count = 0
        else:
            ans[len(S)-i] += count//2 
            ans[len(S)-i-1] += count//2 +1
            count = 0

for a in ans:
    print(a, end=" ")

Submission status: Runtime Error

Solution code:
import math

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

cd = (c * d) // math.gcd(c, d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = a // c
a_d = a // d
a_cd = a // cd

ans = b - b_c - b_d + b_cd - a + a_c + a_d - a_cd

if a % c != 0 and a % d!= 0:
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import math
def cal_lcm(x, y):
    return (x * y) // math.gcd(x, y)

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

cd = cal_lcm(c,d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = a // c
a_d = a // d
a_cd = a // cd

ans = b - b_c - b_d + b_cd - a + a_c + a_d - a_cd

if a % c != 0 and a % d!= 0:
    ans += 1

print(ans)

Submission status: Runtime Error

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

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

cd = lcm(c,d)
b_c = b // c
b_d = b // d
b_cd = b // cd
a_c = a // c
a_d = a // d
a_cd = a // cd

ans = b - b_c - b_d + b_cd - a + a_c + a_d - a_cd

if a % c != 0 and a % d!= 0:
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import string

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: int(x * y / math.gcd(x, y))

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = il()
    MX = B - A + 1

    ret = 0
    ret += B // C
    ret += B // D
    ret -= (A - 1) // C
    ret -= (A - 1) // D
    ret -= B // lcm(C, D)
    ret += (A - 1) // lcm(C, D)
    # print(int(MX - ret))

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


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import gcd

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


divC = B//C - (A-1)//C
divD = B//D - (A-1)//D
divL = B//lcm - (A-1)//lcm

print((B-A+1) - divC - divD + divL)

Submission status: Runtime Error

Solution code:
#C
import math
a, b, c, d = map(int, input().split())
bb = b - (b // c) - (b // d) + (b // (c * d / math.gcd(c, d)))
aa = a - (a // c) - (a // d) + (a // (c * d / math.gcd(c, d)))

print((bb-aa))

Submission status: Runtime Error

Solution code:
import fractions
A,B,C,D=map(int,input().split())
#B以下のものの数からA-1以下のものの数を引く
e=fractions.gcd(C,D)
a_c=(A-1)//C #A-1以下のCの倍数の個数
b_c=B//C  #B以下のCの倍数の個数
a_d=(A-1)//D
b_d=B//D
a_cd=A//e
b_cd=B//e
s=A-1-(a_c+a_d-a_cd)　＃A-1以下の数字のうちCでもDでも割り切れないものの個数
t=B-(b_c+b_d-b_cd)　#B以下の数字の
u=t-s
print(u)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

U = B - A + 1
U_c = U // C
U_d = U // D
U_cd = U // (C * D // gcd(C, D))

ans = U - (U_c + U_d - U_cd)
if A % 4 == 0 or B % 4 == 0:
    ans -= 1
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C,D = list(map(int,input().split()))
import math
E = C * D // math.gcd(C,D)
total = B - B // C - B // D + B // E
F = A-1
total -= F - F // C - F // D + F // E
print(total)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = list(map(int,input().split()))
A -= 1
lcn = C * D / math.gcd(C,D) 
m_n = B - B // C - B // D + B // lcn
min_n = A - A // C - A // D + A // lcn
print(int(m_n-min_n))

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = list(map(int,input().split()))
A -= 1
lcn = C * D / math.gcd(C,D) 
m_n = B - B // C - B // D + B // lcn
min_n = A - A // C - A // D + A // lcn
print(m_n-min_n)

Submission status: Runtime Error

Solution code:
def main():
    from fraction import gcd
    a,b,c,d = map(int,input().split())
    m = int(c*d/gcd(c,d))
    c_=math.ceil(a/c)*c
    d_=math.ceil(a/d)*d
    c__ = math.floor(b/c)*c
    d__ = math.floor(b/d)*d
    m_ = math.ceil(a/m)*m
    m__ = math.floor(b/m)*m
    print(int(b-a-((c__-c_)//c+(d__-d_)//d-(m__-m_)//m)))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    import math
    a,b,c,d = map(int,input().split())
    m = int(c*d/math.gcd(c,d))
    c_=math.ceil(a/c)*c
    d_=math.ceil(a/d)*d
    c__ = math.floor(b/c)*c
    d__ = math.floor(b/d)*d
    m_ = math.ceil(a/m)*m
    m__ = math.floor(b/m)*m
    print(int(b-a-((c__-c_)//c+(d__-d_)//d-(m__-m_)//m)))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
A,B,C,D=list(map(int,stdin.readline().strip().split()))
C_A=(A-1)//C
C_B=B//C
D_A=(A-1)//D
D_B=B//D
CD=lcm(C,D)
CD_A=(A-1)//(CD)
CD_B=B//(CD)
# CD_A=0
# CD_B=0
print((1+B-A)-((C_B-C_A)+((D_B-D_A)-(CD_B-CD_A))))

Submission status: Runtime Error

Solution code:
from math import gcd, floor

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

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

calculate = lambda number, divider: number - floor(number / divider)
num = lambda number1, number2, divider: calculate(number2, divider) - calculate(number1 - 1, divider)
# print(
#     num(A, B, C),
#     num(A, B, D),
#     lcm(C, D),
#     B - A + 1 - num(A, B, C),
#     B - A + 1 - num(A, B, D),
#     floor(B / lcm(C, D)) - floor(A / lcm(C, D)),
# )

answer = B - A + 1 - (B - A + 1 - num(A, B, C) + B - A + 1 - num(A, B, D) - floor(B / lcm(C, D)) - floor(A / lcm(C, D)))
print(answer)

Submission status: Runtime Error

Solution code:
from math import gcd, floor

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

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

calculate = lambda number, divider: number - floor(number / divider)
num = lambda number1, number2, divider: calculate(number2, divider) - calculate(number1 - 1, divider)
print(
    num(A, B, C),
    num(A, B, D),
    lcm(C, D),
    B - A + 1 - num(A, B, C),
    B - A + 1 - num(A, B, D),
    floor(B / lcm(C, D)) - floor(A / lcm(C, D)),
)

answer = B - A + 1 - (B - A + 1 - num(A, B, C) + B - A + 1 - num(A, B, D) - floor(B / lcm(C, D)) - floor(A / lcm(C, D)))
print(answer)
# (40 - 10 + 1) - 5 = 26
# 12, 18, 24, 30, 36

# (40 - 10 + 1) - 4 = 27
# 16, 24, 32, 40

# 10, 11, 13, 14, 15, 16, 17, 19
# 20, 21, 22, 23, 25, 26, 27, 28, 29
# 31, 32, 33, 34, 35, 37, 38, 39, 40
# 26

# a and b

# num = 0
# for number in range(A, B + 1):
#     # if number % CD != 0:
#     if number % C != 0 and number % D != 0:
#         num += 1

# print(num)

Submission status: Runtime Error

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


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


A = A - 1

ans = B - (B // C) - (B // D) + (B // (lcm(C, D)))
p = (A - (A // C) - (A // D) + (A // (lcm(C, D))))

print(ans - p)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
#import math
#import itertools
#import statistics
#import numpy as np
#import collections
#n = int(input())
a, b, c, d = list(map(int, input().split()))
#b = list(map(int, input().split()))

#10 11  13 14 15  17  19 20 21 22 23  25 26 27 28 29 
# 31  33 34 35  37 38 39  
lcm = a*b/math.gcd(a, b)
diff = b-a+1
d1 = (b//c - a//c)
d2 = (b//d - a//d)
a1 =  int((b//lcm-a//lcm))

print(diff-d1-d2+a1)

Submission status: Runtime Error

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

#10 11  13 14 15  17  19 20 21 22 23  25 26 27 28 29 
# 31  33 34 35  37 38 39  
lcm = a*b/math.gcd(a, b)
diff = b-a+1
d1 = (b//c - a//c)
d2 = (b//d - a//d)
a1 =  int((b//lcm-a//lcm))

print(diff-d1-d2+a1)

Submission status: Runtime Error

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

n_c=math.floor(b/c)-math.ceil(a/c)+1
n_d=math.floor(b/d)-math.ceil(a/d)+1
cd=c*d/math.gcd(c,d)
n_cd=math.floor(b/cd)-math.ceil(a/cd)+1
print(base-n_c-n_d+n_cd)