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


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


#print(len([x for x in range(A,B) if x%2!=0 and x%3!=0]))

size=B-A+1
#C
C2=A%C
if C2 is 0:
    Csize=size
else:
    C2=C-C2
    Csize=size-C2

#D
D2=A%D
if D2 is 0:
    Dsize=size
else:
    D2=D-D2
    Dsize=size-D2

cd =lcm(C,D)

#c,dの最小公倍数
cd2=A%cd
if cd2 is 0:
    CDsize=size
else:
    cd2=cd-cd2
    CDsize=size-cd2

#Cの個数
Cq=(Csize-1)//C
print(Cq)

#Dの個数
Dq=(Dsize-1)//D
print(Dq)

#CDの個数
CDq=(CDsize-1)//cd
print(CDq)

Q=(Cq+1)+(Dq+1)-(CDq+1)
Q=size-Q
print(Q)












"""
listsize=B-A-1
Q=0
for i in range(listsize+1):
    number=i+A
    if number % C is not 0 and number % D is not 0:
        Q+=1
print(Q)
"""

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)
E = lcm(C, D)
sample = B-A
ans = sample - ((B/C-A/C) + (B/D-A/D)-(B/E-A/E))
print(ans)

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)
E = lcm(C, D)
sample = B-A
ans = sample - ((B//C-A//C) + (B//D-A//D)-(B//E-A//E))
print(ans)

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)
E = lcm(C, D)
sample = B-A
ans = sample - ((B//C-A//C) + (B//D-A//D)-(B//E-A//E))
print(ans)

Submission status: Runtime Error

Solution code:
A,B,C,D = input().split()
count = 0
start = int(A)
finish = int(B)
ite = 100
for i in range(ite):
  if i == ite-1:
    nums = list(range(start *i, finish ))
    else:
      nums = list(range(start *i, start*(i+1) ))
  tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
  count += len(tmp)
print(count)

Submission status: Runtime Error

Solution code:
A,B,C,D = input().split()
count = 0
start = int(A)
finish = int(B)
ite = 10000000000
for i in range(ite):
  if i == ite-1:
    nums = list(range(start *i, finish ))
    else:
      nums = list(range(start *i, start*(i+1) ))
  tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
  count += len(tmp)
print(count)

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)


#print(len([x for x in range(A,B) if x%2!=0 and x%3!=0]))

size=B-A+1
#C
C2=A%C
if C2 is 0:
    Csize=size
else:
    C2=C-C2
    Csize=size-C2

#D
D2=A%D
if D2 is 0:
    Dsize=size
else:
    D2=D-D2
    Dsize=size-D2

cd =lcm(C,D)

#c,dの最小公倍数
cd2=A%cd
if cd2 is 0:
    CDsize=size
else:
    cd2=cd-cd2
    CDsize=size-cd2

#Cの個数
Cq=Csize//C

#Dの個数
Dq=Dsize//D

#CDの個数
CDq=CDsize//cd

Q=size-(Cq+Dq)+CDq
Q=Q-1
print(Q)












"""
listsize=B-A-1
Q=0
for i in range(listsize+1):
    number=i+A
    if number % C is not 0 and number % D is not 0:
        Q+=1
print(Q)
"""

Submission status: Runtime Error

Solution code:
A,B,C,D = input().split()
count = 0
start = int(A)
finish = int(B)
ite = finish/start
for i in range(ite):
	if i == ite-1:
      nums = list(range(start *i, finish ))
    else:
	  nums = list(range(start *i, start*(i+1) ))
	tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
    count += len(tmp)
print(count)

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)
E = lcm(C, D)
sample = B-A+1
ans = sample - ((B//C-A//C) + (B//D-A//D)-(B//E-A//E))
print(ans)

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)


#print(len([x for x in range(A,B) if x%2!=0 and x%3!=0]))

size=B-A+1
#C
C2=A%C
if C2 is 0:
    Csize=size
else:
    C2=C-C2
    Csize=size-C2

#D
D2=A%D
if D2 is 0:
    Dsize=size
else:
    D2=D-D2
    Dsize=size-D2

cd =lcm(C,D)

#c,dの最小公倍数
cd2=A%cd
if cd2 is 0:
    CDsize=size
else:
    cd2=cd-cd2
    CDsize=size-cd2

#Cの個数
Cq=Csize//C

#Dの個数
Dq=Dsize//D

#CDの個数
CDq=CDsize//cd

Q=size-(Cq+Dq-CDq)
print(Q)












"""
listsize=B-A-1
Q=0
for i in range(listsize+1):
    number=i+A
    if number % C is not 0 and number % D is not 0:
        Q+=1
print(Q)
"""

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)


#print(len([x for x in range(A,B) if x%2!=0 and x%3!=0]))

size=B-A-1
#C
C2=A%C
if C2 is 0:
    Csize=size
else:
    C2=C-C2
    Csize=size-C2

#D
D2=A%D
if D2 is 0:
    Dsize=size
else:
    D2=D-D2
    Dsize=size-D2

cd =lcm(C,D)

#c,dの最小公倍数
cd2=A%cd
if cd2 is 0:
    CDsize=size
else:
    cd2=cd-cd2
    CDsize=size-cd2

#Cの個数
Cq=Csize//C

#Dの個数
Dq=Dsize//D

#CDの個数
CDq=CDsize//cd

Q=size-(Cq+Dq-CDq)
print(Q)












"""
listsize=B-A-1
Q=0
for i in range(listsize+1):
    number=i+A
    if number % C is not 0 and number % D is not 0:
        Q+=1
print(Q)
"""

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)


#print(len([x for x in range(A,B) if x%2!=0 and x%3!=0]))

size=B-C-1

#C

C2=A%C
if C2 is 0:
    Csize=size
else:
    C2=C-C2
    Csize=size-C2

#D
D2=A%D
if D2 is 0:
    Dsize=size
else:
    D2=D-D2
    Dsize=size-D2

cd =lcm(C,D)

#c,dの最小公倍数
cd2=A%cd
if cd2 is 0:
    CDsize=size
else:
    cd2=cd-cd2
    CDsize=size-cd2

#Cの個数
Cq=Csize//C

#Dの個数
Dq=Dsize//D

#CDの個数
CDq=CDsize//cd

Q=size-(Cq+Dq-CDq)
print(Q)












"""
listsize=B-A-1
Q=0
for i in range(listsize+1):
    number=i+A
    if number % C is not 0 and number % D is not 0:
        Q+=1
print(Q)
"""

Submission status: Runtime Error

Solution code:
A,B,C,D = input().split()
nums = list(range(int(A), int(B)+1))
tmp = [x for x in nums if not x%int(C) == 0 and not x%int(D) == 0]
print(len(tmp))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import math

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

if __name__ == '__main__':
    a, b, c, d = list(map(int, input().split()))
    bc = b // c
    bd = b // d
    ac = (a - 1) // c
    ad = (a - 1) // d
    l = lcm(c, d)

    ans = (b - (bc + bd)) - ((a - 1) - (ac + ad)) + b // l
    print(ans)

Submission status: Runtime Error

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

def gcd(n, m):
	while m:
		n, m = m, n % m
	return n

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

if c == 1 or d == 1:
    print(hoge)
    print(b - a + 1)
    exit()

if a == 1:
    div_a = 0
else:
    div_a = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)
div_b = b // c + b // d - b // lcm(c, d)

print(b - a + 1 - div_b + div_a)

Submission status: Runtime Error

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

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


a=list(range(A,B+1))

b=[]
b=list(filter(lambda x: x % C!=0 and x % D!=0,a))

print(len(b))


"""
listsize=B-A-1
Q=0
for i in range(listsize+1):
    number=i+A
    if number % C is not 0 and number % D is not 0:
        Q+=1
print(Q)
"""

Submission status: Runtime Error

Solution code:
import math
from fractions import gcd
 
def number_calc(A,B,x):
  	if A%x == 0:
      left = A//x
    else:
      left = A//x + 1
    right = B//x
    res = max(right-left+1,0)
    return res
 
A,B,C,D = map(int,input().split())
 
ans = B-A+1
ans -=number_calc(A,B,C)
ans -=number_calc(A,B,D)
lcm = (C*D)//gcd(C,D)
ans +=number_calc(A,B,lcm)
 
print(ans)

Submission status: Runtime Error

Solution code:
import copy
import math

inp = str(input())
# inp = "314159265358979323 846264338327950288 419716939 937510582"
inp = inp.split(" ")
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
d = int(inp[3])

h = c * d / math.gcd(c, d)
e = int(b / c) - int((a-1) / c)
f = int(b / d) - int((a-1) / d)
g = int(b / h) - int((a-1) / h)

print((b-a+1)-(e+f-g))

Submission status: Runtime Error

Solution code:
import math

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

QC = 0 #Cで割り切れる
QD = 0 #Dで割り切れる
QCD = 0 #CとDで割り切れる

CD = int(C * D / math.gcd(C, D)) #最大公約数
print(CD)

#約数の個数を求める
QC = (B // C) - (A // C)
if A % C == 0:
        QC += 1

QD = (B // D) - (A // D)
if A % D == 0:
        QD += 1

QCD = (B // CD) - (A // CD)
if A % CD == 0:
        QCD += 1

N = B-A+1
CorD = QC+QD-QCD

print(N-CorD)

Submission status: Runtime Error

Solution code:

import math

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

A -= 1

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

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

print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import math

def gcd(a, b):
    return int(math.gcd(a, b))

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
import math

def gcd(a, b):
    return math.gcd(a, b)

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

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans + 1)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
	if a < b:
		a,b = b,a
	while b:
		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())
a3 = b // c - (a-1) // c
b3 = b // d - (a-1) // d
if c < d:
	c,d = d,c
width = b - a + 1
c3 = b//lcm(c,d) - (a-1)//lcm(c,d)
print(int(width - a3 - b3 + c3))

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import math

def gcd(a, b):
    return math.gcd(a, b)

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    return int(n/a) + int(n/b) - int(n/lcm(a,b))

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Runtime Error

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

def su(a,b,c,d):
    count = 0
    for _ in range(a//c, (b+1)//c):
        count += 1
    for _ in range(a//d, (b+1)//d):
        count += 1
    for _ in range(a//lcm(c,d), (b+1)//lcm(c,d)):
        count -= 1

    print(b+1-a-count)
    
def main():
    a,b,c,d = map(int,input().split())
    su(a,b,c,d)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

X = sympy.lcm(C, D)
x = (B//X)-(A-1)//X

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

Submission status: Runtime Error

Solution code:
import math
A, B, C, D=map(int, input().split())
 
num = []
for i in [C, D, C*D/math.gcd(C,D)]:
  num.append(int(B/i) -int((A-1)/i) )
print(B- A + 1 -num[0]-num[1] +num[2])

Submission status: Runtime Error

Solution code:
N, L = map(int, input().split())
 
if L > -1:
  N_eat = 1
elif N+L-1 < 1:
  N_eat = N
else:
  N_eat = 1-L

pie = N*(N+1)/2 +N*(L-1) - (L + N_eat-1) 
print(pie)

Submission status: Runtime Error

Solution code:

import sys
input = sys.stdin.readline
#-------------------------------------
import math

a,b,c,d = map(int,input().split())
cd = c*d
bcnt = b-(b//c+b//d-b//(cd//math.gcd(c,d)))
acnt = 0
if a>1:
        a -= 1
        acnt = a-(a//c+a//d-a//(cd//math.gcd(c,d)))

print(bcnt-acnt)

Submission status: Runtime Error

Solution code:
import math

def LCM(a,b):
    return a*b/math.gcd(a,b)

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print(int(result))

Submission status: Runtime Error

Solution code:
import math

def LCM(a,b):
    return a*b/math.gcd(a,b)

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print('{}'.format((int(result))))

Submission status: Runtime Error

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n % m
  
  
g = m
l = (c*d)/g

s = int((a-1)/c)
t = int((a-1)/d)
u = int((a-1)/l)
x = int(b/c)
y = int(b/d)
z = int(b/l)

B = b - x - y + z
A = a - 1 - s - t + u

print(B - A)

Submission status: Runtime Error

Solution code:
import math

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

count = B - A + 1
lcd_of_CD = C * D // math.gcd(C, D)

count -= B // C
count += (A - 1) // C
count -= B // D
count += (A - 1) // D
count += B // lcd_of_CD
count -= (A - 1) // lcd_of_CD

print(count)

Submission status: Runtime Error

Solution code:
from math import gcd
A, B, C, D = [int(n) for n in input().split()]
print((B-A) - ((B//C + B//D) - (A//C + A//D)) + (B//(C*D//gcd(C,D)) - A//(C*D//gcd(C,D))))

Submission status: Runtime Error

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n%m
  
  
g = n
l = (c*d)/g

s1 = (a-1)/c
t1 = (a-1)/d
u1 = (a-1)/l
x1 = b/c
y1 = b/d
z1 = b/l

A = (x1 + x2 - x3) - (s1 + t1 - u1)

print(A)

Submission status: Runtime Error

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n%m
  
  
g = n

s1 = (a-1)/c
t1 = (a-1)/d
u1 = (a-1)/g
x1 = b/c
y1 = b/d
z1 = b/g

A = (x1 + x2 - x3) - (s1 + t1 - u1)

print(A)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
cd=int(c*d/(math.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
cd=int(c*d/(math.gcd(c,d)))
#print(cd)
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(cd)
cd2=(a-1)//(cd)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))
#print(str(c3)+" "+str(d3)+" "+str(cd3))

Submission status: Runtime Error

Solution code:
import math

def not_divisible(r, c, d):
    return max(0, int(r - (r//c) - (r//d) + r// ((c * d) // math.gcd(c, d))))

a, b, c, d = list(map(int, input().split(' ')))
res = not_divisible(b, c, d) - not_divisible(a-1, c, d)
print(res)

Submission status: Runtime Error

Solution code:
from math import gcd

A,B,C,D=map(int,input().split())
Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
cddiv = (C*D) // gcd(C, D)
CDdiv = B // (cddiv) - (A-1) // cddiv

print( (B-A+1) - Cdiv - Ddiv + CDdiv )

Submission status: Runtime Error

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

nrofC = (B // C) - ((A-1) // C)
nrofD = (B // D) - ((A-1) // D)

cdlcm = C * D // math.gcd(C,D)
nrofCD = (B // cdlcm) - ((A-1) // cdlcm)

print((B-(A-1)) - nrofC - nrofD + nrofCD)

Submission status: Runtime Error

Solution code:
import math

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

def count(x):
    return x - int(x/c) - int(x/d) + int(x/(c*d/(math.gcd(c,d))))


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

Submission status: Runtime Error

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

print(b-(b//c+b//d-b//cd) - ((a-1)-((a-1)//c+(a-1)//d-(a-1)//cd)))

Submission status: Runtime Error

Solution code:
import fractions
# A, B, C, D = map(int, input().split(' '))
warizan = [ B//C - (A-1)//C, B//D - (A-1)//D, B//(C*D/fractions.gcd(C, D)) - (A-1)//(C*D/fractions.gcd(C, D))]
print(B-(A-1)-(warizan[0]+warizan[1]-warizan[2]))

Submission status: Runtime Error

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


if (c > d) :
    y = c
    z = d
else :
    y = d
    z = c

while(True) :
    amari = y % z
    if(amari==0) :
        break
    y = z
    z = amari

cd = int (c * d / z)

wari = (int(b/c) + int(b/d) - int(b/cd)) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/cd) )))

print(str(b - a - wari + 1))

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split(' '))
warizan = [B//C - (A-1)//C, B//D - (A-1)//D, int(B//(C*D/math.gcd(C, D)) - (A-1)//(C*D/math.gcd(C, D)))]
print(B-(A-1)-(warizan[0]+warizan[1]-warizan[2]))

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split(' ')) #入力
warizan = [B//C - (A-1)//C, B//D - (A-1)//D, int(B//(C*D/math.gcd(C, D)) - (A-1)//(C*D/math.gcd(C, D)))]
print(B-(A-1)-(warizan[0]+warizan[1]-warizan[2]))

Submission status: Runtime Error

Solution code:
c_list = [C*i for i in range(B//C+1)]

d_list = [D*i for i in range(B//D+1)]

koho = [i for i in range(A,B+1)]

for c in c_list:
    try:
        koho.remove(c)
    except ValueError:
        pass

for d in d_list:
    try:
        koho.remove(d)
    except ValueError:
        pass
# print(koho)

print(len(koho))

Submission status: Runtime Error

Solution code:
import fraction

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

a -= 1

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

b_sum = b - (b // c) - (b // d) + (b // lcm)
a_sum = a - (a // c) - (a // d) + (a // lcm)

print(b_sum - a_sum)

Submission status: Runtime Error

Solution code:
import math

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

a -= 1

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

b_sum = b - (b // c) - (b // d) + (b // lcm)
a_sum = a - (a // c) - (a // d) + (a // lcm)

print(b_sum - a_sum)

Submission status: Runtime Error

Solution code:
import math

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

a -= 1

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

b_sum = b - (b // c) - (b // d) + (b // lcm)
a_sum = a - (a // c) - (a // d) + (a // lcm)

print(b_sum - a_sum)

Submission status: Runtime Error

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

cc = []
dd = []
ccc = c
ddd = d
i = 2

while (ccc > i)  :
    if (ccc % i == 0) :
        cc.append(i)
        ccc = ccc / i
    else :
        i += 1
cc.append(i)

i=2
while (ddd > i)  :
    if (ddd % i == 0) :
        dd.append(i)
        ddd = ddd / i
    else :
        i += 1
dd.append(i)

cdz = 1
for cz in cc :
    for i in range(0,len(dd)) :   
        if (cz == dd[i]) :
            cdz = cdz * cz
            del dd[i]
            break

cd = c * d /cdz

wari = (int(b/c) + int(b/d) - int(b/int(cd)) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/int(cd) )))

print(str(b - a - wari + 1))

Submission status: Runtime Error

Solution code:
import math

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

A, B, C, D = (int(x) for x in input().split())

Cu = B//C       #Cの上限
Cd = -(-A//C)   #Cの下限
Du = B//D       #Dの上限
Dd = -(-A//D)   #Dの下限

#Least common multiple
LCMu = B//(lcm(C,D))
LCMd = -(-A//lcm(C,D))
print(lcm(C,D))

C_num = Cu - Cd + 1
D_num = Du - Dd + 1
LCM_num = LCMu - LCMd + 1

C_D_num = C_num + D_num - LCM_num
A_B_num = B - A  + 1

ans = A_B_num - C_D_num
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import fractions as fl

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

#全体の個数
all = b - a + 1
#cとdの最小公倍数
e = c * d // fl.gcd(c, d)
# a以下でcまたはdで割れる個数
r1 = (a-1) // c + (a-1) // d - (a-1) // e
# b以下でcまたはdで割れる個数
r2 = b // c + b // d - b // e
ans = all - (r2 - r1)
print(ans)

Submission status: Runtime Error

Solution code:
import math
import sys

sys.setrecursionlimit(10**7) 

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

A, B, C, D = (int(x) for x in input().split())

Cu = B//C       #Cの上限
Cd = -(-A//C)   #Cの下限
Du = B//D       #Dの上限
Dd = -(-A//D)   #Dの下限

#Least common multiple
LCMu = B//(lcm(C,D))
LCMd = -(-A//lcm(C,D))

C_num = Cu - Cd + 1
D_num = Du - Dd + 1
LCM_num = LCMu - LCMd + 1

C_D_num = C_num + D_num - LCM_num
A_B_num = B - A  + 1

ans = A_B_num - C_D_num
print(ans)

Submission status: Runtime Error

Solution code:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = c * d / frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = b // c
b2 = b // d
b3 = b // e
print(b - a + 1 - ((b1+b2-b3) - (a1 + a2 - a3))

Submission status: Runtime Error

Solution code:
import fractions as frac
[a,b,c,d] = [int(i) for i in input().split()]
e = c * d / frac.gcd(c,d)
a1 = (a-1) // c
a2 = (a-1) // d
a3 = (a-1) // e
b1 = b // c
b2 = b // d
b3 = b // e
print(b - a + 1 (-a1 - a2 + a3 - b3 + b1 + b2))

Submission status: Runtime Error

Solution code:
def lcm(a, b):
    import math
    return a // math.gcd(a, b) * b


def f(x, c, d):
    res = x
    res -= x//c
    res -= x//d
    res += x//lcm(c,d)
    return res

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

ans = f(B, C, D) - f(A-1, C, D)
print(int(ans))

Submission status: Runtime Error

Solution code:
def lcm(a, b):
    import math
    return a // math.gcd(a, b) * b


def f(x, c, d):
    res = x
    res -= x//c
    res -= x//d
    res += x//lcm(c,d)
    return res

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

    ans = f(B, C, D) - f(A-1, C, D)
    print(int(ans))

resolve()

Submission status: Runtime Error

Solution code:
import math

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

A, B, C, D = (int(x) for x in input().split())

Cu = B//C
Cd = -(-A//C)
Du = B//D
Dd = -(-A//D)

LCMu = B//(lcm(C,D))
LCMd = -(-A//lcm(C,D))

C_num = Cu - Cd + 1
D_num = Du - Dd + 1
LCM_num = LCMu - LCMd + 1

C_D_num = C_num + D_num - LCM_num
A_B_num = B - A  + 1

ans = A_B_num - C_D_num
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

A, B, C, D = (int(x) for x in input().split())

Cu = B//C       #Cの上限
Cd = -(-A//C)   #Cの下限
Du = B//D       #Dの上限
Dd = -(-A//D)   #Dの下限

#Least common multiple
LCMu = B//(lcm(C,D))
LCMd = -(-A//lcm(C,D))

C_num = Cu - Cd + 1
D_num = Du - Dd + 1
LCM_num = LCMu - LCMd + 1

C_D_num = C_num + D_num - LCM_num
A_B_num = B - A  + 1

ans = A_B_num - C_D_num
print(ans)

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

countB = b - (b // c) - (b // d) + (b // lcm(c,d))
countA = a - 1 - ((a - 1) // c) - ((a - 1) // d) + ((a - 1) // lcm(c,d))

print(countB - countA)

Submission status: Runtime Error

Solution code:
from math import gcd

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

def f(n, c, d):
    x = n
    x -= n//c
    x -= n//d
    x += n//lcm(c,d)
    return x

a, b, c, d = map(int, input().split())
r = f(b, c, d) - f(a-1, c, d)
print(r)

Submission status: Runtime Error

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

## b = qa + r
#b = C
#a = D
#r = C%D
#while r != 0:
#    b = a
#    a = r
#    r = b%a
#gcd = a
gcd = math.gcd(C, D)
CDlcm = C*D//gcd

total = B-(A-1)
Cmuls = B//C - (A-1)//C
Dmuls = B//D - (A-1)//D
CDmuls = B//CDlcm - (A-1)//CDlcm
ans = total - Cmuls - Dmuls + CDmuls
print(ans)

Submission status: Runtime Error

Solution code:
def gcd(a,b):
    while b != 0:
        temp = b
        b = a%b
        a = temp
    return a
A,B,C,D = map(int,input().split())
if C >=D ;
    lc = int(C*D/gcd(C,D))
else: lc = int(C*D/gcd(D,C))
A = A-1
A_n = A - (A//C + A//D - A//lc)
B_n = B - (B//C + B//D - B//lc)
print(int(B_n-A_n))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())

a = set()
for i in range(m):
    a_tmp = int(input())  # int(input())
    a.add(a_tmp)

# a = [1 for i in range(m)]

dp = [0] * (n + 1)
for i in range(n + 1):
    if i in a:
        dp[i] = 0
    else:
        if i == 0:
            dp[i] = 1
        elif i == 1:
            dp[i] = 1
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007
print(dp[n])

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int, input().split())	
e = math.floor((c * d / math.gcd(c, d)))
 
 
f=math.floor((a-1)/c) 
g=math.floor(b/c) 
h=math.floor((a-1)/d) 
k=math.floor(b/d) 
l=math.floor((a-1)/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(x-y-z+w)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int, input().split())	
e = (c * d // math.gcd(c, d))
 
 
f=math.floor((a-1)/c) 
g=math.floor(b/c) 
h=math.floor((a-1)/d) 
k=math.floor(b/d) 
l=math.floor((a-1)/e)
m=math.floor(b/e)
x=round(b-a+1)
y=round(g-f)
z=round(k-h)
w=round(m-l)
print(x-y-z+w)

Submission status: Runtime Error

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

count = b - a
def baisuu(n):
    return int((b // n) - (a // n + bool(a % n)))
print(count - baisuu(c) - baisuu(d) + baisuu(c * d / math.gcd(c, d)))

Submission status: Runtime Error

Solution code:
# a から bで　cでもdでも割り切れないものの数を調べる
import math
#from fractions import gcd
Input = input()
a, b, c, d = Input.split()
a, b, c, d = int(a), int(b), int(c), int(d)
delta_c = b//c - a//c
delta_d = b//d - a//d
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
#    return (x * y) // gcd(x, y)
cd = lcm(c, d)
delta_cd = b//cd - a//cd
num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')

Submission status: Runtime Error

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

count = b - a
def baisuu(x, n):
    if a <= x <= b:
        return x, n * (b // n)
    else:
        return baisuu(x + n, n)
x1, x2 = baisuu(c, c)
x3, x4 = baisuu(d, d)
print(count - ((x2 - x1) // c) - ((x4 - x3) // d))

Submission status: Runtime Error

Solution code:
import math

temp = input().split(" ")
min = int(temp[0])
max = int(temp[1])
divisor1 = int(temp[2])
divisor2 = int(temp[3])
divisors = [divisor1,divisor2] if divisor1 > divisor2 else [divisor2, divisor1]


gcdDivisors = math.gcd(divisors[0], divisors[1]);
lcmDivisors = divisor1 * divisor2 / gcdDivisors

divNum1 = math.floor(max / divisor1) - math.floor((min - 1) / divisor1);
divNum2 = math.floor(max / divisor2) - math.floor((min - 1) / divisor2);
divNumLcm = math.floor(max / lcmDivisors) - math.floor((min -1) / lcmDivisors);

divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = max - min + 1 - divNumTotal

print(int(ans))

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x)) 
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
struct Info
{
    int a;
    int b;

    Info() {}
    Info(int a, int b)
    {
      this->a = a;
      this->b = b;
    }
    bool operator<(const Info &another) const
    {
        return b < another.b;
    };
};

vector<Info> is;
int main() {
  int n, a, b;
  cin >> n;
  rep(i, n) {
    cin >> a >> b;
    Info* in = new Info(a, b);
    is.push_back(*in);
  }
  sort(is.begin(), is.end());
  int pre = is[0].b;
  int l = 0;
  int i = 0;
  for(auto e : is){
    l += e.a;
    if(l > e.b) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Submission status: Runtime Error

Solution code:
import math

temp = input().split(" ")
min = int(temp[0])
max = int(temp[1])
divisor1 = int(temp[2])
divisor2 = int(temp[3])
divisors = [divisor1,divisor2] if divisor1 > divisor2 else [divisor2, divisor1]

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

gcdDivisors = gcd(divisors[0], divisors[1]);
lcmDivisors = divisor1 * divisor2 / gcdDivisors

divNum1 = math.floor(max / divisor1) - math.floor((min - 1) / divisor1);
divNum2 = math.floor(max / divisor2) - math.floor((min - 1) / divisor2);
divNumLcm = math.floor(max / lcmDivisors) - math.floor((min -1) / lcmDivisors);

divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = max - min + 1 - divNumTotal

print(int(ans))

Submission status: Runtime Error

Solution code:
import sys
N,K = map(int,input().split())
cnt_nodes = (N-1)*(N-2) // 2
if K > cnt_nodes:
	print(-1)
	sys.exit(0)
    
print((N-1)*(N) // 2 - K)
cnt = 0
for i in range(1,N):
	for j in range(i+1,N+1):
		if cnt >= (N-1)*(N) // 2 - K:
			break
		print(i,j)
		cnt += 1
	else:
		continue
	break

Submission status: Runtime Error

Solution code:
    import math
    def Euclidean(x,y):
        if y == 0:
            return x
        else:
            return Euclidean(y,x%y)
     
    A,B,C,D = [int(x) for x in input().split()]
    count = B - A + 1
    E = Euclidean(C,D)
    F = C*D/E
     
    C_ = math.floor(B/C) - math.floor((A-1)/C)
    D_ = math.floor(B/D) - math.floor((A-1)/D)
    C_and_D = math.floor(B/F) - math.floor((A-1)/F)
    print(count - int(C_ + D_ - C_and_D))

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
E = (C*D)//math.gcd(C,D)
e = B//E - (A-1)//E
answer = B-A+1-(c+d-e)
print(answer)

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())
c = B//C - (A-1)//C
d = B//D - (A-1)//D
E = lcm(C,D)
e = B//E - (A-1)//E
answer = B-A+1-(c+d-e)
print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import gcd from fractions

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

def f(x, a, b):
    return x - x // a - x // b + x // lcm(a, b)

def main():
    a, b, c, d = map(int, input().split())
    print(f(b, c, d) - f(a - 1, c, d))

if __name__ == '__main__':
    main()