Problem:


Score : 300 points

Problem Statement

You are given four integers A, B, C, and D. Find the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Constraints

1\leq A\leq B\leq 10^{18}

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

Print the number of integers between A and B (inclusive) that can be evenly divided by neither C nor D.

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368



Sample input:
4 9 2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
yoso=b-a+1
kobai=fractions.gcd(c,d)
AC=c-(a%c)
if AC==c:
  AC=0
BC=b%c
AD=d-(a%d)
if AD==d:
  AD=0
BD=b%d
A_kobai=a%kobai
if A_kobai==kobai:
  A_kobai=0
B_kobai=b%kobai
C=0
if AC+BC>(yoso%c):
  C=yoso//c
else:
  C=(yoso//c)+1
D=0
if AD+BD>(yoso%d):
  D=yoso//d
else:
  D=(yoso//d)+1
CD=0
if A_kobai+B_kobai>(yoso%kobai):
  CD=yoso//kobai
else:
  CD=(yoso//kobai)+1
print(yoso+CD-C-D)

Submission status: Wrong Answer

Solution code:
A,B,C,D= (int(i) for i in input().split())  


if B<C:
    if B<D:
        print(int(B-A+1))
    else:
        ist=(A-A%D)/D
        ien=(B-B%D)/D
        print(int(B-A+1-ien+ist-1))
elif B<D:
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    print(int(B-A+1-ien+ist-1))
else:
    ist,ien,jst,jen,kst,ken=1,1,1,1,1,0
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    jst=(A-A%D)/D
    jen=(B-B%D)/D
    ist=(A-A%(C*D))/(C*D)
    ien=(B-B%(C*D))/(C*D)
    print(int(B-A+1-ien+ist-1-jen+jst-1+ken-kst+1))

Submission status: Wrong Answer

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

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

def main():
    a, b, c, d = map(int, input().split())
    l = lcm(c, d)

    if a % c == 0:
        c_bai = (b - b % c) / c - ((a - a % c) / c + 1)
    else:
        c_bai = (b - b % c) / c - (a - a % c) / c
    if a % d == 0:
        d_bai = (b - b % d) / d - ((a - a % d) / d + 1)
    else:
        d_bai = (b - b % d) / d - (a - a % d) / d
    if a % l == 0:
        l_bai = (b - b % l) / l - ((a - a % l) / l + 1)
    else:
        l_bai = (b - b % l) / l - ((a - a % l) / l)
    print(int(b - a + 1 - c_bai - d_bai + l_bai))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# In[129]:


import fractions


# In[124]:


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


# In[137]:


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


# In[138]:


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[143]:


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


# In[144]:


print(ans2 - ans1)


# In[ ]:

Submission status: Wrong Answer

Solution code:
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

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

CD = lcm(C,D)
ac = int((A-1)/C)
bc = int(B/C)
ad = int((A-1)/D)
bd = int(B/D)
acd = int((A-1)/CD)
bcd = int(B/CD)
cnt = B - bc - bd + bcd - (A-1) + ac + ad - acd
print(cnt)

Submission status: Wrong Answer

Solution code:
import fractions
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 = int((c * d) / fractions.gcd(c, d))

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

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int, input().split())
N=B-A+1-((B//C-A//C+B//D-A//D)-(B//(C*D)-A//(C*D)))
if (A%C==0 or A%D==0):
    N-=1
    if (B%C==0 or C%D==0):
        N-=1
print(N)

Submission status: Wrong Answer

Solution code:
import math
import fractions

A, B, C, D = map(int, input().split())
N = B - A + 1  #整数列の長さ

if C == D:
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    print(N-tmp)
elif fractions.gcd(C,D):
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    mod = A % D
    tmp += math.ceil((N-mod)/D)
    mod = A % (D*C)
    tmp -= math.ceil((N-mod)/(D*C))
    print(N-tmp)
elif max(C,D)%min(C,D) == 0:
    tmp = 0   #最後にNから引く
    mod = A % min(C, D)
    tmp += math.ceil((N-mod)/min(C, D))
    print(N-tmp)
else:
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    mod = A % D
    tmp += math.ceil((N-mod)/D)
    mod = A % (D*C)
    tmp -= math.ceil((N-mod)/(D*C))
    print(N-tmp)

Submission status: Wrong Answer

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

A_div_byCorD = int((A-1)/C) + int((A-1)/D) - int((A-1)/(C*D))
B_div_byCorD = int(B/C) + int(B/D) - int(B/(C*D))
#print(A_div_byCorD)
#print(B_div_byCorD)
canbedivided = B_div_byCorD - A_div_byCorD

print(B-A+1 - canbedivided)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions

input=stdin.readline().rstrip().split()
A=int(input[0])
B=int(input[1])
C=int(input[2])
D=int(input[3])
if C!=D:
    output=0
    Cmax=int(B/C)
    Cmin=int((A-1)/C)
    Dmax=int(B/D)
    Dmin=int((A-1)/D)
    CD=C*D/fractions.gcd(C,D)
    CDmax=int(B/CD)
    CDmin=int((A-1)/CD)
    output=(B-A+1)-((Cmax-Cmin)+(Dmax-Dmin)-(CDmax-CDmin))
    #print(Cmax,Cmin,Dmax,Dmin,CDmax,CDmin)
    print(output)
else:
    output=0
    Cmax=int(B/C)
    Cmin=int((A-1)/C)
    output=(B-A+1)-(Cmax-Cmin)
    #print(Cmax,Cmin)
    print(output)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
p = 0
cntC = int(B / C) - int(A / C)
cntD = int(B / D) - int(A / D)

#a,bの最大公約数
def gcd(C, D):
    while D:
        C, D = D, C % D
    return C

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


CD = lcm(C, D)

cntCD = int(B / CD) - int(A / CD)

# print(cntC, cntD, cntCD, CD)
calc = (B-A+1) - (cntC + cntD - cntCD)

if A % C == 0:
    p += 1
if B % C == 0:
    p += 1
if A % D == 0:
    p += 1
if B % D == 0:
    p += 1

if p > 0:
    if p % 2 == 0:
        calc -= 1

print(calc)

Submission status: Wrong Answer

Solution code:
A , B , C , D = map(int,input().split())
lst = []
for i in range(A,B):
    if i % C !=0 and i % D != 0:
        lst.append(i)
print(len(lst))

Submission status: Wrong Answer

Solution code:
# 2019/06/22
# AtCoder Beginner Contest 131 - C

import fractions
# Least Common Multiple
def lcm_fgf(a, b):
    return int(a * b / fractions.gcd(a, b))

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

clist = list()
dlist = list()
cdlist = list()

cd = lcm_fgf(c, d)

wkccnt = (b - a) // c
wkdcnt = (b - a) // d
wkcdcnt = (b - a) // cd
rem1 = (b - a + 1) % c
rem2 = (b - a + 1) % d

candiv = wkccnt + wkdcnt - wkcdcnt
ans = (b - a + 1) - candiv - 1

# Output
print(ans)

Submission status: Wrong Answer

Solution code:

#最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
    # print(gcd(a,b))

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

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

    diff = B - A
    count_c = diff // C
    count_d = diff // D
    count_union = diff // lcm(C, D)

    print(diff - count_c - count_d + count_union)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A,B,C,D = map(int,input().split())
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%(gcd(C,D)) == 0 and B%(gcd(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)
elif C == D:
    print((B-A+1) - C_div)
elif C%D==0 or D%C==0:
    if C > D:
        print((B-A+1) - D_div)
    else:
        print((B-A+1) - C_div)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

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

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

def main():
    a, b, c, d = map(int, input().split())
    l = lcm(c, d)

    if a % c == 0:
        c_bai = (b - b % c) / c - ((a - a % c) / c + 1)
    else:
        c_bai = (b - b % c) / c - (a - a % c) / c
    if a % d == 0:
        d_bai = (b - b % d) / d - ((a - a % d) / d + 1)
    else:
        d_bai = (b - b % d) / d - (a - a % d) / d
    if a % l == 0:
        l_bai = (b - b % l) / l - ((a - a % l) / l + 1)
    else:
        l_bai = (b - b % l) / l - ((a - a % l) / l)
    print(b - a + 1 - c_bai - d_bai + l_bai)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

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

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

n = math.ceil(A / C)
m = math.floor(B / C)
if m >= n:
  count_div += m - n + 1

l = math.ceil(A / D)
k = math.floor(B / D)
if k >= l:
  count_div += k - l + 1

j = math.ceil(A / lcm(C, D))
i = math.floor(B / lcm(C, D))
if i >= j:
  count_div -= i - j + 1

print(B - A + 1 - count_div)

Submission status: Wrong Answer

Solution code:
numbers = input().split(' ')

a = int(numbers[0])	
b = int(numbers[1])
c = int(numbers[2])
d = int(numbers[3])

e = c * d
i = int(a / c) + 1
j = int(a / d) + 1
k = int(a / e) + 1
count = 0
print(j)
while c * i < b:
	i += 1
	count += 1
while d * j < b:
	j += 1
	count += 1
while e * k < b:
	k += 1
	count -= 1
print(b - a - count + 1)

Submission status: Wrong Answer

Solution code:
num=list(map(int,input().split()))
j=0
for i in range(num[0],num[1]):
    if not(i%num[2]==0 or i%num[3]==0):
        j =j+1
        
print(j)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

def num_of_mod0(mod):
    if A%mod == 0:
        start = A
    else:
        start = (int(A/mod) +1) * mod

    end = (int(B /mod)) * mod

    return (end - start) / mod +1

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

Submission status: Wrong Answer

Solution code:
import math
def hcf(a,b):
	if(a==0):
		return b
	# if(a==0):
	# 	return b
	return hcf(b%a,a)
a,b,c,d = list(map(int,input().split()))
cka = int(math.floor(b/c) - math.ceil(a/c)) + 1
dka = int(math.floor(b/d) - math.ceil(a/d)) + 1
lcm = int((c*d)/(hcf(c, d)))
# print("lcm",lcm)
dcka = int(math.floor(b/lcm) - math.ceil(a/lcm)) + 1
# print(cka,dka,dcka)
# print(b-a+1dcka)
print(int(b-a+1-cka-dka+dcka))

Submission status: Wrong Answer

Solution code:
# 2019/06/22
# AtCoder Beginner Contest 131 - C

import fractions
# Least Common Multiple
def lcm_fgf(a, b):
    return int(a * b / fractions.gcd(a, b))

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

clist = list()
dlist = list()
cdlist = list()

cd = lcm_fgf(c, d)

wkccnt = (b - a) // c
wkdcnt = (b - a) // d
wkcdcnt = (b - a) // cd
rem1 = (b - a + 1) % c
rem2 = (b - a + 1) % d

print(wkccnt, wkdcnt, wkcdcnt)

candiv = wkccnt + wkdcnt - wkcdcnt
ans = (b - a + 1) - candiv - 1

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
#C
from math import ceil, floor
from fractions import gcd
A,B,C,D = map(int, input().split())
X = int(C * D / gcd(C, D))

def retLR(A, B, num):
    #return A <= l*num < r*num <= B, length
    l = ceil(A/num)
    r = floor(B/num)
    if r*num < A and B < l*num :
        length = 0
    elif (r*num < A and l*num <= B) or (A <= r*num and B < l*num) : 
        length = 1
    else:
        length = r - l + 1
    return length

a1 = retLR(A,B,C)
a2 = retLR(A,B,D)
a3 = retLR(A,B,X)

if C == D:
    subst = a1
else:
    subst = a1 + a2 - a3
ans = (B - A + 1) - subst
print(ans)

Submission status: Wrong Answer

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

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

A,B,C,D = map(int,input().split(" "))
min_C = int(B/C)-int((A-1)/C)
min_D = int(B/D)-int((A-1)/D)
lcm = int((C*D)/gcd(C,D))
min_lcm = int(B/lcm)-int((A-1)/lcm)
print(B-A-min_C-min_D+min_lcm+1)

Submission status: Wrong Answer

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

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

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

lcm_num = lcm(c,d)
c_num = (b//c - a//c) if a%c!=0 else (b//c - a//c + 1)
d_num = (b//d - a//d) if a%d!=0 else (b//d - a//d + 1)
ba_num = b//lcm_num - a//lcm_num

print(b-a+1-(c_num+d_num-ba_num) if b-a+1-(c_num+d_num-ba_num) > 0 else 0)

Submission status: Wrong Answer

Solution code:

a,b,c,d=map(int,input().split())
cc=int((b-a+1)/c)
dd=int((b-a+1)/d)
i = 0
f = [c]
x = 10000000
k = [c, d]

while x != 0:
    x = max(k) % min(k)
    if x != 0:
        f.append(x)
    k.sort()
    k[1] = x
cd=int((b-a+1)/(c*d))
print(b-a+1-cc-dd+cd)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
  if b > a:
    a,b = b,a
  while b:
    a, b = b , (a%b)
  return a

  
a,b,c,d = map(int,input().split())
g = c*d // gcd(c,d)
num = g - (g//c) - (g//d) + 1
n_a = (a//g) + (a%g != 0)
n_b = (b//g) + (b%g != 0)


count = 0

if n_b == n_a:
  mi = (a-1)-((n_a-1)*g)
  mib = b - (n_b -1)*num
  count += (mib - (mib//c) - (mib//d)) - (mi - (mi//c) - (mi//d))
elif n_b - n_a == 1 :
  mi = (a-1)-((n_a-1)*g)
  count += num - (mi - (mi//c) - (mi//d))
  nb = b-(n_b-1)*g
  count += nb - (nb//c) - (nb//d)
else:
  count = 0
  #count += num * (n_b - n_a - 1)
  mib = b - (n_b-1)*num
  mi = a-1
  count += (b - (b//c) - (b//d) + (b//g)) - (mi - (mi//c) - (mi//d) + (mi//g))
  
  
print(count)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
s = 0
start = a // c
end = b // c
if start * c < a:
    s += end - (start + 1) + 1
else:
    s += end - start + 1
if d % c != 0:
    start = a // d
    end = b // d
    if start * d < a:
        s += end - (start + 1) + 1
    else:
        s += end - start + 1
def gcd(x, y):
    while y != 0:
        (x, y) = (y, x % y)
    return x
    return gcd
last = c * d // gcd(c, d)
start = a // last
end = b // last
if start * c < a:
    s -= end - (start + 1) + 1
else:
    s -= end - start + 1
print((b - a + 1) - s)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    if b>a:
        (a,b)=(b,a)
    d = a%b
    if d==0:
        return b
    else:
        return gcd(b,d)

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

count = 0
koubai = 0
flagc =0
flagd =0
while b-a+1>c*d-1:
    a += c*d
    koubai += 1

flagc = a%c+1
flagd = a%d+1

nokori = b+1 - a 
while nokori >= min(flagc,flagd):
    x = min(flagc,flagd)
    nokori -= x
    flagc -= x
    flagd -= x
    count += x-1
    if flagc == 0:
        flagc = c
    if flagd == 0:
        flagd = 0


print(count+nokori+koubai*(c*d-c-d+gcd(c,d)))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

if C == 1 or D == 1 :
    print(0)
elif min(C,D) > B :
    print(A - B + 1)
elif max(C,D) % min(C,D) == 0 :
    Z = min(C,D)
    ans = B - A + 1 - countX(Z)
    print(ans + 1)
elif A % C == 0 and B % C == 0:
    print(z)
else :
    ans = B - A + 1

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

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
e = int(c*d/fractions.gcd(c, d))
if a%c != 0:
	fc = (int(a/c)+1)*c
else:
	fc = (int(a/c))*c
tc = (int(b/c))*c
sc = int((tc - fc)/c)+1

if a%d != 0:
	fd = (int(a/d)+1)*d
else:
	fd = (int(a/d))*d
td = (int(b/d))*d
sd = int((td - fd)/d)+1

if a%e != 0:
	fe = (int(a/e)+1)*e
else:
	fe = (int(a/e))*e
te = (int(b/e))*e
se = int((te - fe)/e)+1

ss = (b-a+1)-(sc+sd-se)
print(ss)

Submission status: Wrong Answer

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

lcm= c * d // fractions.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: Wrong Answer

Solution code:
import fractions

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

if C == D:
    duplicate = C
elif C > D and C % D == 0:
    duplicate = C
elif D > C and D % C == 0:
    duplicate = D
else:
    duplicate = C * D // fractions.gcd(C, D)

cCnt = (B - A) // C
dCnt = (B - A) // D
duplicateCnt = (B - A) // duplicate

print(B - A - cCnt - dCnt + duplicateCnt)

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

U = B - A + 1

nA = ( math.floor(B / C) ) - (math.ceil(A / C)) +1

nB = ( math.floor(B / D) ) - (math.ceil(A / D)) +1

saisyoukoubaisuu = C * D / fractions.gcd(C, D)

saisyoukoubaisuu = int(saisyoukoubaisuu)

nAB = (B//saisyoukoubaisuu) -(B//saisyoukoubaisuu) + 1

print( U -(nA + nB - nAB) )

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A,B,C,D = map(int,input().split())
if A%C==0 or A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 or B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(gcd(C,D)) == 0 or B%(gcd(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)
elif C == D:
    print((B-A+1) - C_div)
elif C%D==0 or D%C==0:
    if C > D:
        print((B-A+1) - D_div)
    else:
        print((B-A+1) - C_div)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):

    while b:

        a, b = b, a % b

    return a

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

X = (C * D) // gcd(C, D)
Y = (C + D) // gcd(C, D) - 1

#print(X,Y)

N = A % X 
N_S = N-1
UA = Y - (N_S // C + N_S // D)

#print(UA)
M = B % X
UB = M // C + M // D 

#print(UB)


SA =  A + ( X - N )
SB =  B - M 
#print(SA,SB)
count = (SB - SA) // X * Y 

#print(count)
add = count + UA + UB
    
Z = B - A - add + 1

if C == 1:
    Z = 0
if D == 1:
    Z = 0
print(Z)

Submission status: Wrong Answer

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(a,b):
    x = a
    y = b
    mod = b
    while x % y != 0:
        mod = x % y
        x = b
        y = mod
    return mod

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

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

Submission status: Wrong Answer

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

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

A,B,C,D = map(int,input().split(" "))
min_C = int(B/C)-int((A-1)/C)
min_D = int(B/D)-int((A-1)/D)
lcm = int((C*D)/gcd(C,D))
min_lcm = int(B/lcm)-int((A-1)/lcm)
print(B-A-min_C-min_D+min_lcm+1)

Submission status: Wrong Answer

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

e = int(b // c)
f = int(a // c)
if f == a / c:
    g = e - f + 1
else:
    g = e - f

h = int(b // d)
i = int(a // d)
if i == a / d:
    j = h - i + 1
else:
    j = h - i

import fractions

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

k = int(b // cd)
l = int(a // cd)
if l == a / cd:
    m = k - l + 1
else:
    m = k - l

ans = (b-a) + 1 - (g + j - m)
print(int(ans))

Submission status: Wrong Answer

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

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

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

allnum =  B -A +1
E = lcm(C, D)

Cnum = int(B/C) - int((A-1)/C)
Dnum = int(B/D) - int((A-1)/D)
Enum = int(B/E) - int((A-1)/E)

num = allnum - Cnum - Dnum + Enum
print(int(num))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
s=0
h=0
sno=int(a/c)
sno2=int(a/d)
i=sno
i2=sno2
while(h<b):
   h=i*c
   if(h<a):
       s+=1
   elif(h%d==0):
       s+=1
   i+=1
h=0
while(h<b):
   h=i2*d
   if(h<a):
       s+=1
   i2+=1
print((b-a)-(i+i2)+s+2+(sno+sno2))

Submission status: Wrong Answer

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

import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    token = lines[0].split(" ")
    a = int(token[0])
    b = int(token[1])
    c = int(token[2])
    d = int(token[3])

    return (a, b, c, d)

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c

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

def solve(a, b, c, d):
    
    e = lcm(c, d)

    k = (b - a) // c
    l = (b - a) // d
    m = (b - a) // e
    
    return int(((b - a) + 1) - ((k + 1) + (l + 1) - (m + 1)))


def main():
    # 出力

    # print("%s" % solve(*parse_input()))
    print(solve(*parse_input()))


if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
import fractions

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int(lis[2]*lis[3]/gCD)
AmodC=lis[0]%lis[2]
if AmodC==0:
    AC=lis[0]
else:
    AC=lis[0]+(lis[2]-AmodC)
AmodD=lis[0]%lis[3]
if AmodD==0:
    AD=lis[0]
else:
    AD=lis[0]+(lis[3]-AmodD)
BC=lis[1]-lis[1]%lis[2]
BD=lis[1]-lis[1]%lis[3]
AmodCD=lis[0]%CD
if AmodCD==0:
    ACD=lis[0]
else:
    ACD=lis[0]+(CD-AmodCD)
BCD=lis[1]-lis[1]%CD
ABC=(BC-AC)/lis[2]+1
ABD=(BD-AD)/lis[3]+1
ABCD=(BCD-ACD)/CD+1
ans=lis[1]-lis[0]+1-int(ABC+ABD-ABCD)

print(ans)
#print(AC,AD,BC,BD,ACD,BCD,ABC,ABD,ABCD)

Submission status: Wrong Answer

Solution code:
import fractions as m
def lcm(x, y):
  return (x * y) / m.gcd(x, y)
  
x = input()
x = str(x).split(" ")
f = 0
 
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])
 
n = b-a+1
 
if c-a%c < n%c :
  f+=1
 
if d-a%d < n%d :
  f+=1
 
if c*d-a%(lcm(c,d)) < n%(lcm(c, d)) :
  f-=1
  
print( n - int(n/d) - int(n/c) + int(n/(lcm(c, d)) - f))

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import fractions
a, b, c, d = map(int, input().split())

# cで割り切れる個数を求める
c_div = (b // c) - (a // c)
#print(c_div)

# dで割り切れる個数を求める
d_div = (b // d) - (a // d)
#print(d_div)

# cとd両方で割り切れる数を求める
cd = (c * d) // fractions.gcd(c, d)
cd_div = (b // cd) - (a // cd)
#print(cd_div)

div =  c_div  + d_div - cd_div

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())
ll = B - A + 1
C_min = 0
D_min = 0
CD_min = 0
for i in range(A,B+1):
  if C_min == 0 and i % C == 0:
    C_min = i
  if i % D == 0 and D_min == 0:
    D_min = i
  if i % C == 0 and i % D == 0 and CD_min == 0:
    CD_min = i
  if C_min > 0 and D_min > 0 and CD_min > 0:
    break
  if ll > C and D_min > 0 and CD_min > 0:
    break
  if ll > D and C_min > 0 and CD_min > 0:
    break
  if ll > C*D and C_min > 0 and D_min > 0:
    break
C_cou = 0
D_cou = 0
CD_cou = 0
if C_min > 0:
	C_cou = (B - C_min) // C + 1
if D_min > 0:
	D_cou = (B - D_min) // D + 1
if CD_min > 0:
	CD_cou = (B - CD_min) // (C*D) + 1
ans = B - A - C_cou - D_cou + CD_cou + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
yoso=b-a+1
kobai=fractions.gcd(c,d)
AC=c-(a%c)
if AC==c:
  AC=0
BC=b%c
AD=d-(a%d)
if AD==d:
  AD=0
BD=b%d
Akobai=a%kobai
if Akobai==kobai:
  Akobai=0
Bkobai=b%kobai
C=0
if AC+BC>(yoso%c):
  C=yoso//c
else:
  C=(yoso//c)+1
D=0
if AD+BD>(yoso%d):
  D=yoso//d
else:
  D=(yoso//d)+1
CD=0
if Akobai+Bkobai>(yoso%kobai):
  CD=yoso//kobai
else:
  CD=(yoso//kobai)+1
print(yoso+CD-C-D)

Submission status: Wrong Answer

Solution code:
A,B,C,D = list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
l=C*D//gcd(C,D)
print(B+1-A -(B//C)+(A-1)//C -(B//D)+(A-1)//D +B//l+(A-1)//l )

Submission status: Wrong Answer

Solution code:

line = input().split()
a,b,c,d = tuple([int(s) for s in line])
base = b-a+1

if c == 1 or d == 1:
    print(0)
else:
    subb_c = int(b/c)
    if a%c == 0:
        subm_c = int(a/c)
    else:
        subm_c = int(a/c) + 1
    c_count = subb_c - subm_c + 1

    subb_d = int(b/d)
    if a%d == 0:
        subm_d = int(a/d)
    else:
        subm_d = int(a/d) + 1
    d_count = subb_d - subm_d + 1

    def gcd(m, n):
        if m < n:
            return gcd(n, m)
        while m%n != 0:
            temp = n
            n = m % n
            m = temp
        return n

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

    mil = lcm(c, d)
    subb_mil = int(b/mil)
    if a%mil == 0:
        subm_mil = int(a/mil)
    else:
        subm_mil = int(a/mil) + 1
    mil_count = subb_mil - subm_mil + 1

    base = base - c_count - d_count + mil_count

    print(base)

Submission status: Wrong Answer

Solution code:
def u(a,b):
  if b == 0:
    return a
  return u(b, a%b)

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

e=int(c/u(c,d)*d)
a=a-1
ac = int(a / c)
bc = int(b / c)
ad = int(a / d)
bd = int(b / d)
ae = int(a / e)
be = int(b / e)

print(b - a - (bc - ac + bd - ad ) + (be - ae))

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
if c==1:
  print(0)
elif d==1:
  print(0)
elif a==b and a%c!=0 and a%d!=0:
  print(1)
else:
  cd = int(c*d/fractions.gcd(c, d))
  waru_c = int(b/c)-int((a-1)/c)
  waru_d = int(b/d)-int((a-1)/d)
  waru_cd = int(b/cd)-int((a-1)/cd)
  print((b-a+1)-(waru_c+waru_d-waru_cd))

Submission status: Wrong Answer

Solution code:
import fractions

parents = list(map(int,input().split(' ')))
All = parents[1] - parents[0]
min_2 = (parents[2]*parents[3]) // fractions.gcd(parents[2], parents[3])

All = All-All//parents[2]-All//parents[3]+All//min_2

if parents[2]>=parents[0] and parents[2]<=parents[1] and parents[2]>=(parents[1]-parents[0]+1):
    All = All-1
if parents[3]>=parents[0] and parents[3]<=parents[1] and parents[3]>=(parents[1]-parents[0]+1):
    All = All-1

if All<0:
    All = 0
print(All)

Submission status: Wrong Answer

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

def getAns(a, b, c):
  if a % c == 0:
    start = a
  else:
    start = a + c - (a % c)
    if start > b:
      return 0
    
  if b % c == 0:
    end = b
  else:
    end = b - c + (b % c)
    if end < a:
      return 0
    
  num_c = max((end - start) // c + 1, 0)
  return num_c

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import fractions
import math

A,B,C,D = map(int,input().split())
lcm = C*D/fractions.gcd(C,D)
def c_in_a2b(c):
    if c > B:
        return 0
    else:
        return (math.floor(B/c) - math.ceil(A/c) + 1)
if C!=D:
    print(int((B-A+1)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(lcm)))
else:
    print(int((B-A+1)- c_in_a2b(C)))

Submission status: Wrong Answer

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

def countNum(nSmall, nLarge, nD):
    # find smaller than nLarge
    largest = math.floor(nLarge / nD) * nD
    smallest = math.ceil(nSmall / nD) * nD

    if largest == 0:
        return 0
    if smallest > largest:
        return 0

    return (largest-smallest) / nD + 1

numC = countNum(A,B,C)
numD = countNum(A,B,D)
numCD = countNum(A,B,(C*D)/fractions.gcd(C,D) )

able = numC + numD - numCD
print(int(B - A + 1 - able))

Submission status: Wrong Answer

Solution code:
a,b,c,d= map(int,input().split())
def gcd(c,d):
    while d!=0:
        c,d=d,c%d
    return c


def lcm(c,d):
    return c*d//gcd(c,d)

a1=0
a2=0
b1=0
b2=0
e1=0
e2=0


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

if(a-1>=c):
    a1=(a-1)//c
else:
    a1=0

if(b>=c):
    b1=b//c
else:
    b1=0

if(a-1>=d):
    a2=(a-1)//d
else:
    a2=0

if(b>=d):
    b2=b//d
else:
    b2=0

if(a-1>=e):
    e1=(a-1)//e
else:
    e1=0

if(b>=e):
    e2=b//e
else:
    e2=0
        
ans=b-a+1-(b1-a1)-(b2-a2)+(e2-e1)

print(int(ans))

Submission status: Wrong Answer

Solution code:
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y!=0:
            z = x%y
            x = y
            y = z
        else:
            return z

# import math
a, b, c, d = map(int, input().split())
b_c = int(b/c)
b_d = int(b/d)
cd = c * d // gcd(c,d)
b_cd = b // cd
bn = b_c + b_d - b_cd
# print("bn:",bn)
a -= 1
a_c = int(a/c)
a_d = int(a/d)
a_cd = a // cd
an = a_c + a_d - a_cd
# print("an:",an)

num = b - a - (bn - an)
print(num)

Submission status: Wrong Answer

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

count=0

for i in range(A,B):
    if i % C != 0:
        if i%D!=0:
            count+=1

print(count)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

x =int(b/c)-int(((a-1)/c))
y =int(b/d)-int(((a-1)/d))
n =lcm(c,d)
xy=int(b/n)-int((a/n))

ans = (b-a+1) - (x+y-xy)
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
#cnt = 0
"""
c2 = b//c - a//c
d2 = b//d - a//d
cd = b//(c*d) - a//(c*d)
print(c2+d2-cd)
"""
a-=1
a2 = a//c + a//d - a//(c*d)
print(b-a-(b//c + b//d - b//(c*d) - a2))

Submission status: Wrong Answer

Solution code:
a, b, c ,d = map(int, input().split())
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
def lcm(a,b):
      return a*b//gcd(a,b)
e = lcm(c, d)
wareru = int(b/c) + int(b/d) - int(b/e) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/e))
print(b-a+1-wareru)

Submission status: Wrong Answer

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

def gcd(C,D):
    r = 10
    while True :
        t = divmod(C,D)
        r = t[1]
        C = D
        D = r
        if r == 0:
            return C
    return D

l_c = int((A+C-1)/C)
u_c = B//C
n_c = u_c - l_c + 1 
l_d = int((A+D-1)/D)
u_d = B//D
n_d = u_d - l_d + 1
CD = C*D // gcd(C,D)
l_cd = int((A+CD-1)/CD)
u_cd = B//CD
n_cd = u_cd - l_cd + 1

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

Submission status: Wrong Answer

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

if c == 1 or d == 1:
    print(0)
elif b < c or b < d:
    print(0)
elif a == b:
    if a%c == 0 or a%d == 0:
        print(0)
    else:
        print(1)
else:
    an1 = math.floor(b/c)
    an2 = math.floor((a-1)/c)
    an3 = math.floor(b/d)
    an4 = math.floor((a-1)/d) 
    gcd = round(c * d / gcd(c, d))
    an5 = math.floor(b/gcd)
    an6 = math.floor((a-1)/gcd)
    an = an1-an2 + an3-an4 -(an5-an6)
    print((b-a+1)-an)

Submission status: Wrong Answer

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

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

E = int(C*D / gcd(C, D))

Anum = A-1 - (int((A-1)/C) + int((A-1)/D) - int((A-1)/E))
Bnum = B - (int(B/C) + int(B/D) - int(B/E))

print(Bnum - Anum)