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 = (int(i) for i in input().split()) 
X= math.gcd(C, D)
l=C*D/X
amari1=A%C
if amari1==0:
    a=A
else:
    a=A+C-amari1
amari2=B%C
b=B-amari2
kazu1=((b-a)/C+1)


amari3=A%D
if amari3==0:
    a=A
else:
    a=A+D-amari3
amari4=B%D
b=B-amari4
kazu2=((b-a)/D+1)

amari5=A%l
if amari5==0:
    c=A
else:
    c=A+l-amari5
amari6=B%l
d=B-amari6
kazu3=((d-c)/l+1)

print(int(B-A+1-kazu1-kazu2+kazu3))

Submission status: Runtime Error

Solution code:
import math

def antidiv(x,l,c,d):
    if x == l:
        return l - (l // c) - (l // d) + 1
    else:
        return x - (x // c) - (x // d) 

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

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


aq = a // l
ar = a % l
bq = b // l
br = b % l

qq = bq - aq - 1
r1 = antidiv(l,l,c,d) - antidiv(ar-1,l,c,d)
r2 = antidiv(br,l,c,d)

ans = qq * antidiv(l,l,c,d) + r1 + r2

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

C_comp = (B//C) - ((A-1)//C)
D_comp = (B//D) - ((A-1)//D)
CD_comp = (B//lcm(C,D)) - ((A-1)//lcm(C,D))

print((B - A + 1) - (C_comp + D_comp - CD_comp))

Submission status: Runtime Error

Solution code:
if A%C==0 and A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(C*D) == 0 and B%(C*D) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)
if C == 1 or D == 1:
    print(0)
else:
    print((B-A+1) - C_div -D_div + CD_div))

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())
ans = b-a+1
dim = 0
ca = a % c
if not ca:
    dim +=1
da = a % d
if not da:
    dim +=1
cd = lcm(c,d)
cda = a%cd
if not cda:
    ans+=1
dim+= (b-a+ca)//c
dim+= (b-a+da)//d
ans += (b-a+cda)//cd
print(ans-dim)

Submission status: Runtime Error

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

num = 0
for i in range(int(a),int(b)+1):
  if i % c != 0:
    if i % d != 0:
      num += 1
print(num)

Submission status: Runtime Error

Solution code:
import sys,math
input = sys.stdin.readline

A,B,C,D = map(int,input().split())
lcm =  (C*D)/math.gcd(C,D)
c=0
End = (B//C)+(B//D)-(B//(lcm))
if A != 1:
  Start = ((A-1)//C)+((A-1)//D)-((A-1)//(lcm))
else :
  Start = 1
print(int((B-A+1)-(End-Start)))

Submission status: Runtime Error

Solution code:

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

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

E=C*D//gcd(C,D)
total=0
if A%C==0 and A>=C:
    total += B//C-A//C+1
else:
    total += B // C - A // C

if A%D==0 and A>=D:
    total += B//D-A//D+1
else:
    total += B // D - A// D

if A%E==0 and A>=E:
    total = total- B//E-A//E+1
else:
    total = total - B // E - A // E

print(B-A+1-tot

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

al = b-a+1
# cで割り切れる個数
x = int(b/c) -int((a-1)/c)
# dで割り切れる個数
y = int(b/d) -int((a-1)/d)
# cdの最小公倍数
lcm_xy = int(c*d/math.gcd(c,d))
# cdの最小公倍数で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
print(x,y,xy,al)
print(al-(x+y-xy))

Submission status: Runtime Error

Solution code:
from math import gcd

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

cnt = int(0)

for i in [c, d]:
    t4 = a // i
    if a % i == 0:
        t1 = t4
    else:
        t1 = t4+1
    t2 = b // i

    cnt += int(t2 - t1 + 1)

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

i = lcm
t4 = a // i
if a % i == 0:
    t1 = t4
else:
    t1 = t4 + 1
t2 = b // i

cnt -= int(t2 - t1 + 1)

print(b - a + 1 - cnt)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = list(map(int,input().split()))
dis = B - A + 1
CD = C*D//math.gcd(C,D)
perCfromA = (A-1)//C
perDfromA = (A-1)//D
perCDfromA = (A-1)//CD
perCfromB = B//C
perDfromB = B//D
perCDfromB = B//CD
warikire = (perCfromB + perDfromB -perCDfromB) - (perCfromA + perDfromA -perCDfromA)
warikirenai = dis -warikire
print(warikirenai)

Submission status: Runtime Error

Solution code:
#data=list(input().split())
a,b,c,d=map(int,input().split())
def gcd(x , y):
    if y == 0 
        return x 
    else gcd(y, x%y)

def gys(a,b):
    remainder = gcd(a,b)
    return int(a*b/remainder)

lcmm=gys(c,d)
def ans(n,k):
    return int(n/k)
def x(s):
    return ans(s,c)+ans(s,d)-ans(s,lcmm)
#print(x(b),x(a))
if a%c==0 or a%d==0:
    print(b-a-x(b)+x(a))
else:
    print(b-a+1-x(b)+x(a))

Submission status: Runtime Error

Solution code:
if A%C==0 and A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(C*D) == 0 and B%(C*D) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)
if C == 1 or D == 1:
    print(0)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np
a,b,c,d  = map(int, input().split())
numarray = np.arange(a,b+1,1)
numc = (numarray%c != 0)
numd = (numarray%d != 0)
print(sum(numc * numd))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

import math

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def calc(n, x):
    return n // x

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

def main():
    a, b, c, d = rli()
    lcm_cd = lcm(c, d)
    n_a = a-1 - calc(a-1, c) - calc(a-1, d) + calc(a-1, lcm_cd)
    n_b = b - calc(b, c) - calc(b, d) + calc(b, lcm_cd)
    print(n_b-n_a)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

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

num = 0

import math

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

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





print(str(num))

Submission status: Runtime Error

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

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

cd = lcm(c, d)

# cの倍数とdの倍数の個数を数える
ca = a // c
# print(ca)
cb = b // c
# print(cb)
tmp_c = cb - ca

da = a // d
# print(da)
db = b // d
# print(db)
tmp_d = db - da

cda = a // cd
# print(cda)
cdb = b // cd
# print(cdb)
tmp_cd = cdb - cda
ans = b - a - (tmp_c + tmp_d - tmp_cd) + 1

print(ans)

Submission status: Runtime Error

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

C_s = (A-A%C)//C
C_e = (B-B%C)//C

D_s = (A-A%D)//D
D_e = (B-B%D)//D

C_cnt = C_e - C_s
if A%C==0:
    C_cnt += 1
D_cnt = D_e - D_s
if A%D==0:
    D_cnt += 1

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

lcm_s = (A-A%lcm)//lcm
lcm_e = (B-B%lcm)//lcm

lcm_cnt = lcm_e - lcm_s
if A%lcm==0:
    lcm_cnt += 1

cnt = C_cnt + D_cnt - lcm_cnt
ans = B - A + 1 - cnt
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

n_c = B//C - (A-1)//C
n_d = B//D - (A-1)//D
lcm_cd = C*D // gcd(C,D)
n_cd = B//lcm_cd - (A-1)//lcm_cd

print(B-A+1 - (n_c+n_d-n_cd))

Submission status: Runtime Error

Solution code:

def c(begin, end, num):
    r = end - begin + 1
    if r < num:
        if begin < num < end:
            return 1
        else:
            return 0
    if num == r:
        return 1
    if num < r:
        while begin % num == 0:
            begin += 1
        begin += 1
        r = end - begin + 1
        return 1 + r // num

# N, K = [int(x) for x in input().split(' ')]
import math
A, B, C, D = [int(x) for x in input().split(' ')]

C, D = (C, D) if C < D else (D, C)
CD = (C * D) // math.gcd(C, D)

count = 0

c_count = c(A, B, C)
d_count = c(A, B, D)
cd_count = c(A, B, CD)

if C == D:
    count = c_count
elif D == CD:
    count = c_count + d_count
else:
    count = c_count + d_count - cd_count

print((B - A + 1) - coun

Submission status: Runtime Error

Solution code:
import math

a,b,c,d =map(int,input().split())
tmp = c * d / math.gcd(c,d)
maxt = b-a+1
maxt = maxt - (b//c - a//c+ int(a%c==0)) - (b//d - a//d + int(a%d==0)) + (b//tmp - a//tmp)  

print(int(maxt))

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
num_list = B - A + 1
C_start = int((A/C)+0.99)
C_end = int(B/C)
C_num = C_end - C_start + 1
D_start = int((A/D)+0.99)
D_end = int(B/D)
D_num = D_end - D_start + 1
lcm = C*D/math.gcd(C, D)
lcm_start = int((A/lcm)+0.99)
lcm_end = int(B/lcm)
lcm_num = lcm_end - lcm_start + 1
print(num_list-C_num-D_num+lcm_num)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = list(map(int,input().split()))
dis = B - A + 1

CD = C*D//math.gcd(C,D)
#print(CD)
perCfromA = (A-1)//C
perDfromA = (A-1)//D
perCDfromA = (A-1)//(CD)


perCfromB = B//C
perDfromB = B//D
perCDfromB = B//(CD)

#print(perCfromA,perDfromA,perCDfromA,perCfromB,perDfromB,perCDfromB)
warikire = (perCfromB + perDfromB -perCDfromB) - (perCfromA + perDfromA -perCDfromA)
warikirenai = dis -warikire
print(warikirenai)

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b,c,d = [int(i) for i in input().split()]
C = 0
D = 0
E = 0
'''
for i in range(int(a / max(c,d,lcm(c,d))),b-a):
    print(i)
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
    if C != 0 and D != 0 and E != 0:
        break
'''
for i in range(int(a / lcm(c,d)),b-a):
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
        break

for i in range(int(a / c),b-a):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

for i in range(int(a / d),b-a):
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
        break
#print('')
#print(C,D,E)
c2 = int(b / c) - int(C / c)+1
d2 = int(b / d) - int(D / d)+1
e2 = int(b / lcm(c,d)) - int(E / lcm(c,d))+1
#print(b-a+1,c2,d2,e2)
'''
c1 = list(range(C,b+1,c))
d1 = list(range(D,b+1,d))
e1 = list(range(E,b+1,lcm(c,d)))
print(b-a+1,len(c1),len(d1),len(e1))

print(c1,d1,e1)

print(b-a+1-len(c1)-len(d1)+len(e1))
'''
print(int(b-a+1 - c2 - d2 + e2))

Submission status: Runtime Error

Solution code:
import math

A,B,C,D=map(int,input().split())
num=B-A
numC=num//C
numD=num//D
numCD=int(num//(C*D/math.gcd(C,D)))
ans=num-numC-numD+numCD
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)

v = lcm(c, d)

s = b//c - (a-1)//c
t = b//d - (a-1)//d
u = b//v - (a-1)//v

print((b-a+1) - (s+t-u))

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_comp = B//C - (A-1)//C
D_comp = B//D - (A-1)//D
CD_comp = B//lcm(C,D) - (A-1)//lcm(C,D)

print((B - A + 1) - (C_comp + D_comp - CD_comp))

Submission status: Runtime Error

Solution code:
  while b!=0:
    a,b=b,a%b
  return a

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

c1=B//C
c2=(A-1)//C

cd1=B//((C*D)/gcd(C,D))
cd2=(A-1)//((C*D)/gcd(C,D))

d1=B//D
d2=(A-1)//D


print(int(B-A+1-(c1-c2)-(d1-d2)+(cd1-cd2)))

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = list(map(int, input().split()))
Num = B - A + 1
#print(Num)
NumC = math.floor(B / C) - math.ceil(A /C) + 1
#print(NumC)
NumD = math.floor(B / D) - math.ceil(A /D) + 1
#print(NumD)
CD = (C * D) // math.gcd(C, D)
NumCD = math.floor(B / CD) - math.ceil(A / CD) + 1
#print(NumCD)
print(Num - NumC - NumD + NumCD)

Submission status: Runtime Error

Solution code:
import math

al = b-a+1
# cで割り切れる個数
x = int(b/c) -int((a-1)/c)
# dで割り切れる個数
y = int(b/d) -int((a-1)/d)
# cdの最小公倍数
lcm_xy = int(a*b/math.gcd(a,b))
# cdの最小公倍数で割り切れる個数
xy = int(b/lcm_xy) -int((a-1)/lcm_xy)
#print(x,y,xy,al)
print(al-(x+y-xy))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[90]:


import math


# In[102]:


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


# In[103]:


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


# In[104]:


c_part_a = int((A - 1) / C)
d_part_a = int((A - 1) / D)
cd_part_a = int((A - 1) / lcm)

c_part_b = int(B / C)
d_part_b = int(B / D)
cd_part_b = int(B / lcm)


# In[105]:


ans1 = (A-1) - (c_part_a + d_part_a - cd_part_a)
ans2 = B - (c_part_b + d_part_b - cd_part_b)


# In[106]:


print(ans2 - ans1)


# In[ ]:

Submission status: Runtime Error

Solution code:
import math

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

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

CD = int(C * D / math.gcd(C, D))
cd = int(B/CD) - int((A-1)/CD)

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

Submission status: Runtime Error

Solution code:
import math
import sys
sys.setrecursionlimit(100000)
A, B, C, D = map(int, input().split())
U = B - A + 1


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


def sten(st, en, x):
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st) // x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
MofD = sten(A, B, D)
MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
import numpy as np
a,b,c,d  = map(int, input().split())
count = 0
numarray = np.arange(a,b+1,1)
numc = (numarray%c != 0)
numd = (numarray%d != 0)
sum(numc * numd)

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

sa = B - A + 1

C2 = (B // C) - ((A - 1) // C)
D2 = (B // D) - ((A - 1) // D)

CD = lcm(C, D)

CD2 = (B // CD) - ((A - 1) // CD)

print(sa - (C2 + D2 - CD2))

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())
count = 0
if a%c==0:
    lower1 = a//c
else:
    lower1 = a//c + 1
if a%d==0:
    lower2 = a//d
else:
    lower2 = a//d + 1
if a%lcm(c,d)==0:
    lower3 = a//lcm(c,d)
else:
    lower3 = a//lcm(c,d) + 1
higher1 = b//c
higher2 = b//d
higher3 = b//lcm(c,d)


count = higher1 - lower1 + 1 + higher2 - lower2 + 1 - higher3 - lower3 + 1

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

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
num_list = B - A + 1
C_start = int((A/C)+0.99)
C_end = int(B/C)
C_num = C_end - C_start + 1
D_start = int((A/D)+0.99)
D_end = int(B/D)
D_num = D_end - D_start + 1
lcm = C*D//math.gcd(C, D)
lcm_start = int((A/lcm)+0.99)
lcm_end = int(B/lcm)
lcm_num = lcm_end - lcm_start + 1
print(num_list-C_num-D_num+lcm_num)

Submission status: Runtime Error

Solution code:
import math

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

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

CD = C * D / math.gcd(C, D)
cd = int(B/CD) - int((A-1)/CD)

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

Submission status: Runtime Error

Solution code:
import math


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


def main(str):
    input = str.split()
    a = int(input[0])
    b = int(input[1])
    c = int(input[2])
    d = int(input[3])
    cd = lcm(c, d)

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


if __name__ == "__main__":
    str = input()
    print(main(str))

Submission status: Runtime Error

Solution code:
# CとDの最小公倍数を求める
# CとDのそれぞれの倍数の数を求めて最小公倍数で割る
import math

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


A,B,C,D = map(int,input().split())
E = lcm(C,D)
c = (A-1)//C + 1 if A!=1 else 1
d = (A-1)//D + 1 if A!=1 else 1
e = (A-1)//E + 1 if A!=1 else 1
cde = [[c,C], [d,D], [e,E]]
cnt_cde = []
for x,y in cde:
    if x*y < B:
        cnt_cde.append((B-x*y)//y+1)
    elif x*y == B:
        cnt_cde.append(1)
    else :
        cnt_cde.append(0)
answer = B-A+1-(cnt_cde[0]+cnt_cde[1]-cnt_cde[2])
print(answer)

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = list(map(int, input().split()))
Num = B - A + 1
#print(Num)
NumC = math.floor(B / C) - math.ceil(A /C) + 1
#print(NumC)
NumD = math.floor(B / D) - math.ceil(A /D) + 1
#print(NumD)
CD = (C * D) // math.gcd(C, D)
NumCD = math.floor(B / CD) - math.ceil(A /CD) + 1
#print(NumCD)
print(Num - NumC - NumD + NumCD)

Submission status: Runtime Error

Solution code:
//usr/bin/env picoc $0 - $@;exit
#include <stdio.h>
int main(){
  long long a,b,c,d,cnt;
  cnt = 0;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  //printf("%lld%lld%lld%lld",a,b,c,d);
  for(int i=a;i<=b;i++){
    if(i % c != 0 && i % d != 0){
      cnt++;
    }
  }
  printf("%lld\n",cnt);
}

Submission status: Runtime Error

Solution code:
import math 
def lcm(a, b):
    return (a*b)/math.gcd(a, b)
a = [int(i) for i in input().split()]
k = a[1]//a[2] - (a[0] - 1)//a[2]
r = a[1]//a[3] - (a[0] - 1)//a[3]
s = a[1]//(int(lcm(a[2],a[3]))) - (a[0] - 1)//int((lcm(a[2],a[3])))
print((a[1] - a[0] + 1 - (k + r - s)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
import fractions

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

if C > D :
    C , D = D , C

ans = 0

if A < C :
    ans += C - A
    A = C

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X >= B :
        return 0
    minX = math.ceil(A / X)
    maxX = math.floor(B / X)

    return maxX - minX + 1

# 最小公倍数
Z = C * D / math.fractions(C,D)

ans += B - A + 1 - countX(C) - countX(D) + countX(Z)

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

num_B_C = B // C
num_B_D = B // D
num_B_CD = B // (lcm)

num_A_C = (A-1) // C
num_A_D = (A-1) // D
num_A_CD = (A-1) // (lcm)

num_all = (num_B_C - num_A_C) + (num_B_D - num_A_D) - (num_B_CD - num_A_CD)
result = (B - (A-1)) - num_all

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
p=input().rstrip().split(' ')
a=int(p[0])
b=int(p[1])
c=int(p[2])
d=int(p[3])
e=(b//c)-(a//c)
if (a%c==0 and b%c==0) or (a%c==0):
    e+=1;
f=(b//d) - (a//d);
if (a%d==0 and b%d==0) or (a%d==0):
    f+=1;
g=b-a+1
h=math.gcd(c,d)
i=(c*d)//h
j=b//i
k=e+f-j
l=g-k
print(l)

Submission status: Runtime Error

Solution code:
import math
A,B,C,D = map(int,input().split())
n = B//C
m = (A-1)//C
p = B//D
q = (A-1)//D

x = B//(C*D// math.gcd(C,D))
y = (A-1)//(C*D// math.gcd(C,D))
L = (B-A+1)-((n-m)+(p-q)-(x-y))
print(L)

Submission status: Runtime Error

Solution code:
import math
def unchi(x,m,n):
  r=x//m+x//n-x//(m*n//math.gcd(m,n))
  return r
a,b,c,d=(int(i) for i in input().split())
print(b-a+1-(unchi(b,c,d)-unchi(a-1,c,d)))

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a,b,c,d = [int(i) for i in input().split()]
C = 0
D = 0
E = 0
'''
for i in range(int(a / max(c,d,lcm(c,d))),b-a):
    print(i)
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
    if C != 0 and D != 0 and E != 0:
        break
'''
for i in range(int(a / lcm(c,d)),b-a):
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
        break

for i in range(int(a / c),b-a):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

for i in range(int(a / d),b-a):
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
        break
print('')
#print(C,D,E)
c2 = int(b / c) - int(C / c)
d2 = int(b / d) - int(D / d)
e2 = int(b / lcm(c,d)) - int(E / lcm(c,d))
print(c2,d2,e2)
'''
c1 = list(range(C,b,c))
d1 = list(range(D,b,d))
e1 = list(range(E,b,lcm(c,d)))
print(len(c1),len(d1),len(e1))
'''
#print(c1,d1,e1)

#print(b-a-len(c1)-len(d1)+len(e1))
print(int(b-a - c2 - d2 + e2))

Submission status: Runtime Error

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

cou1=0
cou2=0

y1=int(b/c)
y2=int(b/d)
y3=int(b/lcm)
cou1=b-(y1+y2-y3)

x1=int((a-1)/c)
x2=int((a-1)/d)
x3=int((a-1)/lcm)
cou2=(a-1)-(x1+x2-x3)

print(cou1-cou2)

Submission status: Runtime Error

Solution code:
import math

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

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

cd=b//c-(a-1)//c
dd=b//d-(a-1)//d
cdd=b//(cdlcm)-(a-1)//(cdlcm)

print(round(b-a+1-(cd+dd-cdd)))

Submission status: Runtime Error

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

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())
E = lcm(C,D)
c = (A-1)//C + 1
d = (A-1)//D + 1
e = (A-1)//E + 1
cde = [[c,C], [d,D], [e,E]]
cnt_cde = []
for x,y in cde:
    if x*y < B:
        cnt_cde.append((B-x*y)//y+1)
    elif x*y == B:
        cnt_cde.append(1)
    else :
        cnt_cde.append(0)
answer = B-A+1-(cnt_cde[0]+cnt_cde[1]-cnt_cde[2])
print(answer)

Submission status: Runtime Error

Solution code:
parents = list(map(int,input().split(' ')))
L = parents[1]
if L>0:
    not_add = 0
elif abs(L) > parents[0]-1:
    not_add = parents[0]-1
else:
    not_add = abs(L)
sum = 0
for i in range(parents[0]):
    if not i == not_add:
        sum += (i+L)

print(sum)

Toshikis-MacBook-Pro:Atcoder$ cat con2.py
parents = list(map(int,input().split(' ')))
l_index=[]
sum=0
if parents[2]<parents[3]:
    for i in range(parents[0],parents[1]+1):
        if not i%parents[2]==0:
            l_index.append(i)
    for i in l_index:
        if not i%parents[3]==0:
            sum+=1

else:
    for i in range(parents[0],parents[1]+1):
        if not i%parents[3]==0:
            l_index.append(i)
    for i in l_index:
        if not i%parents[2]==0:
            sum+=1

print(sum)

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

cc = (B//C)-((A-1)//C)
dd = (B//D)-((A-1)//D)

x = lcm(C,D)
ee = (B//x)-((A-1)//x)

ans = (B-A+1)-(cc + dd - ee)
print(ans)

Submission status: Runtime Error

Solution code:
# CとDの最小公倍数を求める
# CとDのそれぞれの倍数の数を求めて最小公倍数で割る
import math

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


A,B,C,D = map(int,input().split())
E = lcm(C,D)
c = (A-1)//C + 1
d = (A-1)//D + 1
e = (A-1)//E + 1
cde = [[c,C], [d,D], [e,E]]
cnt_cde = []
for x,y in cde:
    if x*y < B:
        cnt_cde.append((B-x*y)//y+1)
    elif x*y == B:
        cnt_cde.append(1)
    else :
        cnt_cde.append(0)
answer = B-A+1-(cnt_cde[0]+cnt_cde[1]-cnt_cde[2])
print(cde,cnt_cde,answer)

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)



lcm = lcm(C ,D)


num_all = B - A + 1


ans = 0

z_a_c = int((A-1) / C)
z_b_c = int(B / C)

z_a_b_c = z_b_c - z_a_c


z_a_d = int((A-1) / D)
z_b_d = int(B / D)

z_a_b_d = z_b_d - z_a_d

z_a_l = int((A-1) / lcm)
z_b_l = int(B / lcm)

z_a_b_l = z_b_l - z_a_l


# print(num_all)
# print(z_a_b_c)
# print(z_a_b_d)
# print(z_a_b_l)

ans = num_all - z_a_b_c - z_a_b_d + z_a_b_l


print(ans)

Submission status: Runtime Error

Solution code:
import math

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

n_c = B//C - (A-1)//C
n_d = B//D - (A-1)//D
lcm_cd = C*D // math.gcd(C,D)
n_cd = B//lcm_cd - (A-1)//lcm_cd

print(B-A+1 - (n_c+n_d-n_cd))

Submission status: Runtime Error

Solution code:
from math import gcd

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

def not_devision(a, x, y):
    return (a - int(a/x)) + (a - int(a/y)) - (a - int(a/int((x*y)/gcd(x, y))))

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

Submission status: Runtime Error

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

import math
A,B,C,D=map(int,input().split())
abc=B//C-A//C
abd=B//D-A//D
abcd=(B//(lcm(C,D)))-(A//(lcm(C,D)))
if A%C==0:
    abc+=1
if A%D==0:
    abd+=1
if A%(lcm(C,D))==0:
    abcd+=1



#print(B-A+1)
#print(abc,abd,abcd)
print(B-A+1-(abc+abd-abcd))

Submission status: Runtime Error

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


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


def sten(st, en, x):
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st) / x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
MofD = sten(A, B, D)
MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)

Submission status: Runtime Error

Solution code:
import math
def acinput():
    return list(map(int, input().split(" ")))
def lcm(x, y):
    return x*y // math.gcd(x, y)
    
a, b, c, d = acinput()
l = lcm(c, d)
CD = b//l-(a-1)//l
nC = b//c-(a-1)//c
nD = b//d-(a-1)//d

res = b-a+1-(nC+nD-CD)
print(int(res))

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

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

CD = C * D / math.gcd(C, D)
cd = int(B/CD) - int((A-1)/CD)

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

print(ans)

Submission status: Runtime Error

Solution code:
import math

A,B,C,D = map(int,input().split())
lcm = int(C * D/ math.gcd(C,D))
A = A-1
A_n = A - (A//C + A//D - A//lcm)
B_n = B - (B//C + B//D - B//lcm)
print(int(B_n-A_n))

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)

BdivC=B//C
BdivD=B//D
BdivCD=B//(lcm(C,D))
AdivC=(A-1)//C
AdivD=(A-1)//D
AdivCD=(A-1)//(lcm(C,D))

"""
print(BdivC)
print(BdivD)
print(AdivC)
print(AdivD)
print(BdivCD)
print(AdivCD)
"""

ans=B-(A-1)-(BdivC-AdivC+BdivD-AdivD-BdivCD+AdivCD)

print(ans)

Submission status: Runtime Error

Solution code:
import math
def unchi(x,m,n):
  r=x//m+x//n-x//math.lcm(m,n)
  return r
a,b,c,d=(int(i) for i in input().split())
print(b-a+1-(unchi(b,c,d)-unchi(a-1,c,d)))

Submission status: Runtime Error

Solution code:
import math
inputs = [int(s) for s in input().split()]
a = inputs[0]
b = inputs[1]
c = inputs[2]
d = inputs[3]
count = 0
minCD = min(c, d)
maxCD = max(c, d)

x0 = b-a+1
x1 = b//minCD - (a-1)//minCD
x2 = b//maxCD - (a-1)//maxCD
lcm = minCD * maxCD // math.gcd(minCD, maxCD)
x3 = b//lcm - (a-1)//lcm
print(x0, x1, x2, x3)
if maxCD % minCD == 0:
    print(x0-x1)
else:
    print(x0-(x1+x2-x3))

Submission status: Runtime Error

Solution code:
import math

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

n_c = B//C - (A-1)//C
n_d = B//D - (A-1)//D
lcm_cd = C*D // math.gcd(C,D)
print(lcm_cd)
n_cd = B//lcm_cd - (A-1)//lcm_cd

print(B-A+1 - (n_c+n_d-n_cd))

Submission status: Runtime Error

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


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


def sten(st, en, x):
    st = math.ceil(st/x)*x
    en = math.floor(en/x)*x
    if en >= st:
        n = (en - st)//x + 1
    else:
        n = 0
    return n


MofC = sten(A, B, C)
MofD = sten(A, B, D)
MofCD = sten(A, B, lcm(C, D))

print(U-MofC-MofD+MofCD)

Submission status: Runtime Error

Solution code:
import numpy as np
def acinput():
    return list(map(int, input().split(" ")))




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


a, b, c, d = acinput()
l = lcm(c, d)
CD = b//l-(a-1)//l
nC = b//c-(a-1)//c
nD = b//d-(a-1)//d

res = b-a+1-(nC+nD-CD)
print(int(res))

Submission status: Runtime Error

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

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

ans = 0
for i in range(len(N_list)):
    if N_list[i] % C == 0:
        ans = ans
    elif N_list[i] % D == 0:
        ans = ans
    else:
        ans = ans +1

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)

ac=int(A/C)
bc=int(B/C)
ad=int(A/D)
bd=int(B/D)
acd=int(A/lcm(C,D))
bcd=int(B/lcm(C,D))

if A%C==0:
    c_div=bc-ac+1
else:
    c_div = bc - ac
if B%C==0:
    d_div=bd-ad+1
else:
    d_div = bd - ad
if B%lcm(C,D)==0:
    cd_div=bcd-acd+1
else:
    cd_div = bcd - acd

print(B-A+1-c_div-d_div+cd_div)

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)

cc = (B//C)-((A-1)//C)
dd = (B//D)-((A-1)//D)

x = lcm(C,D)
ee = (B//x)-((A-1)//x)

ans = (B-A+1)-(cc + dd - ee)
print(ans)

Submission status: Runtime Error

Solution code:
import math

A, B, C, D = map(int, input().split())
E = (C * D) // math.gcd(C, D)
num_c = B // C - A // C + (1 if A % C == 0 else 0)
num_d = B // D - A // D + (1 if A % D == 0 else 0)
num_e = B // E - A // E + (1 if A % E == 0 else 0)
num = B - A + 1 - (num_c + num_d - num_e)
print(num)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
e = c*d//math.gcd(c,d)
s = b-a+1
cb = b//c
db = b//d
eb = b//e
ca = a//c
da = a//d
ea = a//e
print(int(s - (cb - ca + db -da - eb + ea)))

Submission status: Runtime Error

Solution code:
import math


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

    def num_of_multiples(st, ed, m):
        a = st % m
        a0 = st + (m - a)
        if a0 > ed:
            return 0
        if a == 0:
            a0 = st
        b = ed % m
        b0 = ed - b
        num = (b0 - a0)
        if num % m != 0:
            raise Exception()
        return (b0 - a0) // m + 1
    
    nc = num_of_multiples(A, B, C)
    nd = num_of_multiples(A, B, D)
    ncd = num_of_multiples(A, B, C * D // math.gcd(C, D))
    print(B - A + 1 - (nc + nd - ncd))


main()

Submission status: Runtime Error

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

#a~bでnで割り切れるものの数
def func(a, b, n):
    answer = (int(b/n) - int((a-1)/n))
    return answer

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

print ((b -a + 1) - func(a,b,c) - func(a,b,d) + func(a,b,lcm))

Submission status: Runtime Error

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

ans_sum=B-A+1
ans_div_c=B//C-A//C
ans_div_d=B//D-A//D
cd=C*D/math.gcd(C,D)
cd=int(cd)
ans_div_cd=B//cd-A//cd
if A%C==0:
	ans_div_c+=1
if A%D==0:
	ans_div_d+=1
if A%cd==0:
	ans_div_cd+=1

print(ans_sum-ans_div_c-ans_div_d+ans_div_cd)