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:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

# n_CD = np.int(np.floor(B/CD) - np.floor((A-1)/CD))
import fractions
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
    
ans = B - A + 1 - n_C - n_D + CDdiv#n_CD
print('{}'.format(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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


def seisu(a, b):
    return (a - (a % b)) / b


def cnt(b, c, d, kobai):
    bc = seisu(b, c)
    bd = seisu(b, d)
    b_kobai = seisu(b, kobai)

    return b - bc - bd + b_kobai


b_num = cnt(b, c, d, kobai)
a_num = cnt(a - 1, c, d, kobai)

ans = b_num - a_num

print(int(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

np = (B - A + 1) + (-(B - A) // C)
nq = (B - A + 1) + (-(B - A) // D)


def coprime(a, b):
    return gcd(a, b) == 1


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


if coprime(C, D) == True:
    npq = (B - A + 1) + (-(B - A) // (C * D))
    print(np + nq - npq)
else:
    npq_ = (B - A + 1) - ((B - A) // lcm(C, D))
    print(np + nq - npq_)

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

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

C_ = len(range(A//C*C if A//C*C ==A else A//C*(C+1),B+1,C))
D_ = len(range(A//D*D if A//D*D ==A else A//D*(D+1),B+1,D))
CD = lcm(C, D)
CD_ = len(range(A//CD*CD if A//CD*CD ==A else A//CD*(CD+1),B+1,CD))

print(B-A+1-C_-D_+CD_)

Submission status: Wrong Answer

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

A, B, C, D = map(int, input().split(" "))
ans = 0
Bc = B // C
Bd = B // D
ck = 0
if C >= D:
        ck = gcd(C, D)
else:
        ck = gcd(D,C)
asb = C*D/ck
Bs = B//asb

newb = B - Bc - Bd + Bs

Ac = (A-1) // C
Ad = (A-1) // D
As = (A-1)//asb

newa = (A-1)-Ac-Ad+As

print(int(newb-newa))

Submission status: Wrong Answer

Solution code:
import fractions

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

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

AtoB =  B - (A-1)

div_C = int(B/C) - int((A-1)/C)
div_D = int(B/D) - int((A-1)/D)
div_CD = int(B/lcm(C,D)) - int((A-1)/lcm(C,D))

print(AtoB , div_C , div_D , div_CD)

print(AtoB - div_C - div_D + div_CD)

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))


f=math.ceil(a/c) 
g=math.floor(b/c) 
h=math.ceil(a/d) 
k=math.floor(b/d) 
l=math.ceil(a/e)
m=math.floor(b/e)
x=b-a+1
y=g-f+1
z=k-h+1
w=m-l+1


print(x-y-z+w)

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 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)
    if c == d:
        an = an1-an2
    else:
        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())
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:
    if A%C==0:
        ist=(A-A%C)/C
    else:
        ist=(A-A%C)/C+1
    ien=(B-B%C)/C
    if A%D==0:
        jst=(A-A%D)/D
    else:
        jst=(A-A%D)/D+1
    jen=(B-B%D)/D
    if A%(C*D)==0:
        kst=(A-A%(C*D))/(C*D)
    else:
        kst=(A-A%(C*D))/(C*D)+1
    
    ken=(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:
import fractions

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

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


def seisu(a, b):
    return (a - (a % b)) / b


def cnt(b, c, d, kobai):
    bc = seisu(b, c)
    bd = seisu(b, d)
    b_kobai = seisu(b, kobai)

    return b - bc - bd + b_kobai


b_num = cnt(b, c, d, kobai)
a_num = cnt(a - 1, c, d, kobai)

ans = b_num - a_num

print(ans)

Submission status: Wrong Answer

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

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

hoge = input().split()
a = int(hoge[0])
b = int(hoge[1])
c = int(hoge[2])
d = int(hoge[3])

hanni = b-a+1
kouyakusu = lcm(c, d)

print(int(hanni-(hanni/c)-(hanni/d)+(hanni/kouyakusu)))

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 = int(divisor1 * divisor2 / gcdDivisors)

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

print(ans)

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def number_calc(A,B,x):
    left = A//x
    right = B//x
    res = right-left
    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: Wrong Answer

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/C)
D_ = math.floor(B/D) - math.floor(A/D)
C_and_D = math.floor(B/F) - math.floor(A/F)
print(count - (C_ + D_ - C_and_D))

Submission status: Wrong Answer

Solution code:
import math
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())

lcm = lcm(C, D)

# minc = C*math.ceil(A/C)
# maxc = C*math.floor(B/C)
# mind = D*math.ceil(A/D)
# maxd = D*math.floor(B/D)
# minlcm = lcm*math.ceil(A/lcm)
# maxlcm = lcm*math.floor(B/lcm)

 # 1~B
nc1 = math.floor(B/C)
nd1 = math.floor(B/D)
nlcm1 = math.floor(B/lcm)

 # 1~A-1
nc2 = math.floor( (A-1)/C )
nd2 = math.floor( (A-1)/D )
nlcm2 = math.floor( (A-1)/lcm )

#if C > B:
#    nc = 0
#if D > B:
#    nd = 0
#if lcm > B:
#    nlcm = 0

nc = nc1 - nc2
nd = nd1 - nd2
nlcm = nlcm1 - nlcm2

n = B - A + 1 - nc - nd + nlcm

print(n)

 # 何故か不正解、納得いかん

Submission status: Wrong Answer

Solution code:
import fractions


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


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

if d < c:
    tmp = c
    c = d
    d = tmp

common = lcm(c, d)

div_c = b//c - (a-1)//c
div_d = b//d - (a-1)//d
div_common = b//common - a//common
print((b - a) + 1 - div_c - div_d + div_common)

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

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

C_ = len(range(math.ceil(A/C)*C,B+1,C))
D_ = len(range(math.ceil(A/D)*D,B+1,D))
CD = lcm(C, D)
CD_ = len(range(math.ceil(A/CD)*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c

import fractions

def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x
'''
def lcm(a,b):
	return a*b//gcd(a,b)
'''
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)) - 1,int(b / lcm(c,d))+2):
    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) - 1,int(b / c)+2):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

for i in range(int(a / d) - 1,int(b / d)+2):
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
        break
'''
#print(lcm(c,d))
#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
'''
'''
if int(b / c) == b/c:
	print('c')
	c2 += 1
if int(b / d) == b/d:
	print('d')
	d2 += 1
if int(b / lcm(c,d)) == b/lcm(c,d):
	print('e')
	e2 += 1
'''
c2 = int(b / c) - int((a-1) / c)
d2 = int(b / d) - int((a-1) / d)
e2 = int(b / (c*d/gcd(c,d))) - int((a-1)/(c*d/gcd(c,d)))
'''
if a % c == 0:
	#print('c')
	c2 += 1
if a % d == 0:
	#print('d')
	d2 += 1
if a % lcm(c,d) == 0:
	#print('e')
	e2 += 1
'''
'''
if E == 0:
	e2 = 0
if C == 0:
	c2 = 0
if D == 0:
	d2 = 0
'''

#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: Wrong Answer

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

cko = math.floor(b/c) - math.floor((a-1)/c)
dko = math.floor(b/d) - math.floor((a-1)/d)
eko = math.floor(b/e) - math.floor((a-1)/e)
print(b-a+1-cko-dko+eko)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def floor(a, b):
  return int((a - a%b)/b)
# def gcd(a, b):
#   while a % b != 0:
#       a, b = b, a % b
#   return a
def lcm(a, b):
  return floor((a * b), gcd(a, b))
input = list(map(int, input().split(' ')))
total_count = input[1] + 1 - input[0]
div_c = floor(input[1], input[2]) - floor(input[0] -1, input[2])
div_d = floor(input[1], input[3]) - floor(input[0] -1, input[3])
div_cd = floor(input[1], lcm(input[2], input[3])) - floor(input[0] -1, lcm(input[2], input[3]))
print(total_count - (div_c + div_d - div_cd))

Submission status: Wrong Answer

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

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d/gcd(c,d))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d/gcd(c,d))




if a%c == 0 or a%d == 0:
    print(int(to_b - to_a))
else:
    print(int(to_b-to_a+1))

Submission status: Wrong Answer

Solution code:
import math
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())

lcm = lcm(C, D)

# minc = C*math.ceil(A/C)
# maxc = C*math.floor(B/C)
# mind = D*math.ceil(A/D)
# maxd = D*math.floor(B/D)
# minlcm = lcm*math.ceil(A/lcm)
# maxlcm = lcm*math.floor(B/lcm)

 # 1~B
nc1 = math.floor(B/C)
nd1 = math.floor(B/D)
nlcm1 = math.floor(B/lcm)

 # 1~A-1
nc2 = math.floor( (A-1)/C )
nd2 = math.floor( (A-1)/D )
nlcm2 = math.floor( (A-1)/lcm )

#if C > B:
#    nc = 0
#if D > B:
#    nd = 0
#if lcm > B:
#    nlcm = 0

nc = nc1 - nc2
nd = nd1 - nd2
nlcm = nlcm1 - nlcm2

n = B - A + 1 - nc - nd + nlcm

print(n)

 # 何故か不正解、納得いかん

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    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())
c_div = int(B/C) - int((A-1)/C)
d_div = int(B/D) - int((A-1)/D)
cd_div = int(B/lcm(C,D)) - int((A-1)/lcm(C,D))
ans = (B-A+1) - c_div - d_div + cd_div
print(ans)

Submission status: Wrong Answer

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

to_a = a - baisu(a,c) - baisu(a,d) + baisu(a,c*d/gcd(c,d))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d/gcd(c,d))

print(to_a)
print(to_b)


if a%c == 0 or a%d == 0:
    print(int(to_b - to_a))
else:
    print(int(to_b-to_a+1))

Submission status: Wrong Answer

Solution code:
import math
a,b,c,d=map(int, input().split())
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
	
e = (c * d / gcd(c, d))


f=math.ceil(a/c) 
g=math.floor(b/c) 
h=math.ceil(a/d) 
k=math.floor(b/d) 
l=math.ceil(a/e)
m=math.floor(b/e)
x=b-a+1
y=g-f+1
z=k-h+1
w=m-l+1
if e<b:
    print(x-y-z)
else:
    print(x-y-z+w)

Submission status: Wrong Answer

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

C_ = int(B//C) - int((A-1)/C)
D_ = int(B//D) - int((A-1)/D)

E = int(C * D / int(fractions.gcd(C, D)))
E_ = int(B//E) - int((A-1)//E)

ans = B - A + 1 - C_ - D_ + E_
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
	if (x > y) :
		x , y = y , x
	r = x % y
	while(r != 0) :
		x = y;
		y = r;
		r = x % y;
	
	return y
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

aKc = int(A / C)
bKc = int(B / C)
aKd = int(A / D)
bKd = int(B / D)

lcm = lcm(C, D)
aKcd = int(A / lcm)
bKcd = int(B / lcm)

sB = B - bKc - bKd + bKcd
sA = A - 1 - aKc - aKd + aKcd

print("{}".format(sB- sA))

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)

CD=lcm(C, D)

dc =  B//C -  (A-1)//C
dd = B//D - (A-1)//D
dcd = B//CD - A//CD

print(B-A+1-dc-dd+dcd)

Submission status: Wrong Answer

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

c=math.floor(B/C)
cc=math.ceil((A-1)/C)

d=math.floor(B/D)
dd=math.ceil((A-1)/D)
CD=(C*D)//fractions.gcd(C,D)
cd=math.floor(B/(CD))
cdcd=math.ceil((A-1)/(CD))

print((B-A+1)-((c-cc)+(d-dd)-(cd-cdcd)))

Submission status: Wrong Answer

Solution code:
import fractions
# input process
inputData = input().split()
A = int(inputData[0])
B = int(inputData[1])
C = int(inputData[2])
D = int(inputData[3])

C_q_num = (B // C) - (A // C)
if (A % C) == 0:
    C_q_num += 1
D_q_num = (B // D) - (A // D)
if (A % D) == 0:
    D_q_num += 1
CD_lcm = (C * D) // fractions.gcd(C, D)
CD_q_num = (B // CD_lcm) - (A // CD_lcm)
if (B % CD_lcm) == 0:
    CD_q_num += 1
print((B - A + 1) - C_q_num - D_q_num + CD_q_num)

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 main():
    A,B,C,D=input().split()
    A=int(A)
    B=int(B)
    C=int(C)
    D=int(D)
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    if A%(C*D/gcd(C,D))!=0:
        CD_min=A-A%(C*D/gcd(C,D))+(C*D/gcd(C,D))
    else:
        CD_min=A
    CD_max=B-B%(C*D/gcd(C,D))
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D/gcd(C,D))+1
    sum= B-A+1-int(C_sum+D_sum-CD_sum)
    return sum

print(main())

Submission status: Wrong Answer

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

A, B, C, D = map(int, input().split(" "))
ans = 0
Bc = B // C
Bd = B // D

ck = gcd(C, D)
asb = C*D/ck
Bs = B//asb

newb = B - Bc - Bd + Bs

Ac = (A-1) // C
Ad = (A-1) // D
As = (A-1)//asb

newa = (A-1)-Ac-Ad+As

print(int(newb-newa))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = np.int(np.floor(B/CD) - np.floor((A-1)/CD))

ans = B-A+1-(n_C+n_D-n_CD)
if ans < 0:
    ans = 0
print('{}'.format(ans))

Submission status: Wrong Answer

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

i = ((b-a)//c) 
j = ((b-a)//d)

f=fractions.gcd(c,d)
f2= c * d / f
k = (b-a)//f2

count = int(i + j - k)

print(b-a-count)

Submission status: Wrong Answer

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

c=math.floor(B/C)
cc=math.ceil((A-1)/C)

d=math.floor(B/D)
dd=math.ceil((A-1)/D)
CD=(C*D)//fractions.gcd(C,D)
cd=math.floor(B/(CD))
cdcd=math.ceil((A-1)/(CD))
if CD>B:
    cd=0
    cdcd=1

print((B-A+1)-((c-cc)+(d-dd)-(cd-cdcd)))

Submission status: Wrong Answer

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

C_ = int(B/C) - int((A-1)/C)
if A % C == 0:                                                                                                                                                                                              
    C_ += 1                                                                                                                                                                                                 
D_ = int(B/D) - int((A-1)/D)
if A % D == 0:                                                                                                                                                                                              
    D_ += 1                                                                                                                                                                                                 

E = C * D / int(fractions.gcd(C, D))
E_ = int(B/E) - int((A-1)/E)
if A % E == 0:                                                                                                                                                                                              
    E_ += 1                                                                                                                                                                                                 

ans = B - A + 1 - C_ - D_ + E_
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
A,B,C,D = map(int,input().split())
if A%C==0 and B%C==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if A%D==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(lcm(C,D)) == 0 and B%(lcm(C,D)) == 0:
    CD_div = (B-A+1)//lcm(C,D) + 1
else:
    CD_div = (B-A+1)//lcm(C,D)
if C==1 or D==1:
    print(0)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

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

c=math.floor(B/C)
cc=math.ceil((A-1)/C)

d=math.floor(B/D)
dd=math.ceil((A-1)/D)
CD=(C*D)//fractions.gcd(C,D)
cd=math.floor(B/(CD))
cdcd=math.ceil((A-1)/(CD))
if CD>B:
    cd=0
    cdcd=1

print((B-A)-((c-cc)+(d-dd)-(cd-cdcd)))

Submission status: Wrong Answer

Solution code:

import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = np.int(np.floor(B/CD) - np.floor((A-1)/CD))

ans = B-A+1-(n_C+n_D-n_CD)
print('{}'.format(0))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = np.int(np.floor(B/CD) - np.floor((A-1)/CD))

ans = B-A+1-(n_C+n_D-n_CD)
if ans < 0:
    ans = 0
print('{}'.format(0))

Submission status: Wrong Answer

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

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

hoge = input().split()
a = int(hoge[0])
b = int(hoge[1])
c = int(hoge[2])
d = int(hoge[3])

hanni = b-a+1
kouyakusu = lcm(c, d)

print(int(hanni-(hanni//c)-(hanni//d)+(hanni//(kouyakusu))))

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

C_ = len(range(math.ceil(A/C)*C,B+1,C))
D_ = len(range(math.ceil(A/D)*D,B+1,D))
CD = (C*D) // fractions.gcd(C, D)
CD_ = len(range(math.ceil(A/CD)*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)

Submission status: Wrong Answer

Solution code:
import fractions
# input process
inputData = input().split()
A = int(inputData[0])
B = int(inputData[1])
C = int(inputData[2])
D = int(inputData[3])

C_q_num = (B // C) - (A // C)
if (B % C) == 0:
    C_q_num += 1
D_q_num = (B // D) - (A // D)
if (B % D) == 0:
    C_q_num += 1
CD_lcm = (C * D) // fractions.gcd(C, D)
CD_q_num = (B // CD_lcm) - (A // CD_lcm)
if (B % CD_lcm) == 0:
    CD_q_num += 1
print((B - A + 1) - C_q_num - D_q_num + CD_q_num)

Submission status: Wrong Answer

Solution code:
import math

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


cc = int(b / c) - int((a-1) / c)
dd = int(b / d) - int((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
# Wprint(min(f))


cd = int(b / (c * d/min(f) )) - int((a-1) / (c * d/min(f) ))

print(b - a+1 - cc - dd + cd)

Submission status: Wrong Answer

Solution code:
import fractions
#import math
def lcm(x, y):
	return int((x * y) / fractions.gcd(x, y));
	#return (x * y) // math.gcd(x, y);

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
num_c = int(b/c) - int((a-1)/c);
num_d = int(b/d) - int((a-1)/d); 
num_cd = int(b/lcm(c, d)) - int((a-1)/lcm(c,d));
print(b - a + 1 -(num_c + num_d - num_cd))

Submission status: Wrong Answer

Solution code:
# 最初に入れておくとinputが早くなる
#import sys
from fractions import gcd
#input = sys.stdin.readline

a, b, c, d = map(int, input().split())
# warikireru = set()
# for i in range(b//c+1):
#    for j in range(b // d+1):
#        k = c ** i * d ** j
#        if(a <= k <= b):
#            warikireru.add(k)
# print(warikireru)
# print(b-a+1-len(warikireru))

k = c * d / gcd(c, d)
x1 = b-b//c-b//d+b//k
a -= 1
x2 = a - a // c - a // d + a // k
print(x1-x2)

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 main():
    A,B,C,D=input().split()
    A=int(A)
    B=int(B)
    C=int(C)
    D=int(D)
    if A%C!=0:
        C_min=A-A%C+C
    else:
        C_min=A
    C_max=B-B%C
    if A%D!=0:
        D_min=A-A%D+D
    else:
        D_min=A
    D_max=B-B%D
    if A%(C*D/gcd(C,D))!=0:
        CD_min=A-A%(C*D/gcd(C,D))+(C*D/gcd(C,D))
    else:
        CD_min=A
    CD_max=B-B%(C*D/gcd(C,D))
    C_sum=(C_max-C_min)/C+1
    D_sum=(D_max-D_min)/D+1
    CD_sum=(CD_max-CD_min)/(C*D/gcd(C,D))+1
    print(C_sum,D_sum,CD_sum)
    sum= B-A+1-int(C_sum+D_sum-CD_sum)
    return sum

print(main())

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
import numpy as np

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

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

a1 = A-1 // C
a2 = A-1 // D

b1 = B // C
b2 = B // D 

ab1 = b1 - a1
ab2 = b2 - a2


lc = lcm(C,D)

a3 = A // lc
b3 = B // lc
ab3 = b3 - a3
res = ab1 + ab2 - ab3
print(abs(A-B)-res)

Submission status: Wrong Answer

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

g = gcd(c,d)
temp = c*d//g

cc = -int(a/c) + int(b/c)
dd = -int(a/d) + int(b/d)
cd = -int(a/temp) + int(b / temp)

print(ans - cc - dd + cd)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
 
def main():
    a,b,c,d = map(int,input().split(" "))
    n = b - a + 1
    cdiv = int(b/c) - int((a-1)/c)
    ddiv = int(b/d) - int((a-1)/d)
    cddiv = int(b/int(c * d / gcd(c, d)))  - int((a-1)/int(c * d / gcd(c, d)))
    print(n - cdiv -ddiv + cddiv)
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# 最初に入れておくとinputが早くなる
import sys
from fractions import gcd
input = sys.stdin.readline

a, b, c, d = map(int, input().split())
# warikireru = set()
# for i in range(b//c+1):
#    for j in range(b // d+1):
#        k = c ** i * d ** j
#        if(a <= k <= b):
#            warikireru.add(k)
# print(warikireru)
# print(b-a+1-len(warikireru))

k = c * d / gcd(c, d)
x1 = b-b//c-b//d+b//k
a -= 1
x2 = a - a // c - a // d + a // k
print(x1-x2)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c

import fractions

def gcd(a, b):
    if b == 0:
        return a
    else:
        while b:
            a, b = b, a % b
        return a
'''
def lcm(a,b):
	return a*b//gcd(a,b)
'''
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)) - 1,int(b / lcm(c,d))+2):
    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) - 1,int(b / c)+2):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

for i in range(int(a / d) - 1,int(b / d)+2):
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
        break
'''
#print(lcm(c,d))
#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
'''
'''
if int(b / c) == b/c:
	print('c')
	c2 += 1
if int(b / d) == b/d:
	print('d')
	d2 += 1
if int(b / lcm(c,d)) == b/lcm(c,d):
	print('e')
	e2 += 1
'''
c2 = int(b / c) - int((a-1) / c)
d2 = int(b / d) - int((a-1) / d)
e2 = int(b / (c*d/fractions.gcd(c,d))) - int((a-1)/(c*d/fractions.gcd(c,d)))
'''
if a % c == 0:
	#print('c')
	c2 += 1
if a % d == 0:
	#print('d')
	d2 += 1
if a % lcm(c,d) == 0:
	#print('e')
	e2 += 1
'''
'''
if E == 0:
	e2 = 0
if C == 0:
	c2 = 0
if D == 0:
	d2 = 0
'''

#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: Wrong Answer

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

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

hoge = input().split()
a = int(hoge[0])
b = int(hoge[1])
c = int(hoge[2])
d = int(hoge[3])

hanni = b-a+1
kouyakusu = lcm(c, d)

print(int(hanni-(hanni/c)-(hanni/d)+(hanni/(kouyakusu))))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
	if (x > y) :
		x , y = y , x
	r = x % y
	while(r != 0) :
		x = y;
		y = r;
		r = x % y;
	
	return y
def lcm(x, y):
    return (x * y) // gcd(x, y)

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

aKc = int(A / C)
bKc = int(B / C)
aKd = int(A / D)
bKd = int(B / D)

lcm = lcm(C, D)
aKcd = int(A / lcm)
bKcd = int(B / lcm)

sB = B - bKc - bKd + bKcd
sA = A - aKc - aKd + aKcd

print("{}".format(sB- sA))

Submission status: Wrong Answer

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

g = gcd(c,d)
temp = c*d//g
cc = -int(a/c) + int(b/c)
dd = -int(a/d) + int(b/d)
cd = -int(a/temp) + int(b / temp)

if c == 1 or d == 1:
    print(0)
else:
    print(ans - cc - dd + cd)

Submission status: Wrong Answer

Solution code:
import math


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


A, B, C, D = map(int, input().split())  # A以上B以下の整数のうち、CでもDでも割り切れないものの個数

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

# B以下の全ての数でCで割れるものの個数hoge
hogeBC = math.floor(B / C)
# A-1以下の全ての数でCで割れるものの個数fuga
fugaA1C = math.floor((A-1) / C)

# B以下の全ての数でDで割れるものの個数
piyoBD = math.floor(B / D)
# A-1以下の全ての数でDで割れるものの個数
toriA1D = math.floor((A-1) / D)

# B以下の全ての数でCとDの最小公倍数で割れるものの個数
yoshiBCD = math.floor(B / (CD_lcm))
# A-1以下の全ての数でCとDの最小公倍数で割れるものの個数
takaA1CD = math.floor((A-1) / (CD_lcm))

# A以上B以下の整数でCで割り切れるものの個数
Ccan = hogeBC-fugaA1C
# A以上B以下の整数でDで割り切れるものの個数
Dcan = piyoBD - toriA1D
# A以上B以下の整数でCでもDでも割り切れるものの個数
CDcan = yoshiBCD - takaA1CD


# A以上B以下でCでもDでも割り切れるものの個数
count = Ccan + Dcan - CDcan
print(abs(B-A)+1 - count)