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:
from fractions import gcd
from math import ceil
def div(n,a,b):
    m = b//n-ceil(a/n)+1
    #print(m)
    return m
a,b,c,d = map(int,input().split())
e = c*d//gcd(c,d)
print(b-a+1-(div(c,a,b) + div(d,a,b) - div(e,a,b)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

A,B,C,D=map(int,input().split(" "))
 
count=0
for i in range(A,B+1):
    if i%C==0 or i%D==0 :
        if i%(C*D)!=0:
            count+=1
                
print(B-A+1-count)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())
ans = 0
x1c = B // C
x1d = B // D
x2c = (A-1) // C
x2d = (A-1) // D
def gcd(x,y):
    if x < y:
        z = x
        x = y
        y = z
    while y != 0:
        x, y = y, x%y
    return x
g = gcd(C,D)
l = (C*D) / g
x1cd = B // l
x2cd = (A-1) // l
ans_B = B - (x1c+x1d-x1cd)
ans_A = (A-1) - (x2c+x2d-x2cd)
ans = ans_B - ans_A
ans = int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())
ans = 0
x1c = B // C
x1d = B // D
x2c = (A-1) // C
x2d = (A-1) // D
def gcd(x,y):
    while y != 0:
        x, y = y, x%y
    return x
g = gcd(C,D)
l = (C*D) / g
x1cd = B // l
x2cd = (A-1) // l
ans_B = B - (x1c+x1d-x1cd)
ans_A = (A-1) - (x2c+x2d-x2cd)
ans = ans_B - ans_A
ans = int(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())
ans = 0
x1c = B // C
x1d = B // D
x2c = (A-1) // C
x2d = (A-1) // D
def gcd(x,y):
    while y != 0:
        x, y = y, x%y
    return x
g = gcd(C,D)
l = (C*D) / g
x1cd = B // l
x2cd = (A-1) // l
ans_B = B - (x1c+x1d-x1cd)
ans_A = (A-1) - (x2c+x2d-x2cd)
ans = ans_B - ans_A
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

A,B,C,D = list(map(int,input().split()))
lcm = C*D/gcd(C,D)
a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
b = (B) - ((B)//C + (B)//D - (B)//lcm)
print(int(b-a))

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 and i%D != 0:
        count += 1
        
print(count)

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)

c_num = b//c - (a-1)//c
d_num = b//d - (a-1)//d
lcm_num = b//lcm - (a-1)//lcm

ans = c_num + d_num - lcm_num

print(math.floor(b-a+1-ans))

Submission status: Wrong Answer

Solution code:
from sys import stdin
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
print(b-a+1-((b//c + b//d - b//(c*d)) - (a//c + a//d + a//(c*d))))

Submission status: Wrong Answer

Solution code:
from sys import stdin

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

total = b-a

total -= (total//c + total//d - total//(c*d))

print(total)

Submission status: Wrong Answer

Solution code:
from sys import stdin

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]

total = b-a+1

total -= (total//c + total//d - total//(c*d))

print(total)

Submission status: Wrong Answer

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

a = a - 1
a_c = int(a/c)
a_d = int(a/d)
a_cd = int(a/(d*c))
a = a - a_c - a_d + a_cd

b_c = int(b/c)
b_d = int(b/d)
b_cd = int(b/(d*c))
b = b - b_c - b_d + b_cd

print(b - a)

Submission status: Wrong Answer

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

from fractions import gcd

def f(i, l, r):
  return r//i - (l-1)//i

cnt = f(c, a, b) + f(d, a, b) - f(gcd(c, d), a, b)

print(b - a + 1 - cnt)

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(a,b):
    res = a*b / fractions.gcd(a,b)
    return res
def f(x,y,z):
    res = x
    res -= x/y
    res -= x/z
    res += x/lcm(y,z)
    return res


A, B, C, D = map(int, input().split())
ans1 = f(B,C,D)
ans2 = f(A-1,C,D)
ans = ans1 - ans2
print(int(ans))

Submission status: Wrong Answer

Solution code:
import fractions

def lcm(a,b):
    res = a*b / fractions.gcd(a,b)
    return res
def ll(x,y,z):
    res = x
    res -= x/y
    res -= x/z
    res += x/lcm(y,z)
    return res


A, B, C, D = map(int, input().split())
ans = ll(B,C,D) - ll(A-1,C,D)
print(int(ans))

Submission status: Wrong Answer

Solution code:
#131c
#整数 A,B,C,D が与えられます。A 以上 B 以下の整数のうち、C でも Dでも割り切れないものの個数を求めてください。
#1≤A≤B≤10^18
#1≤C,D≤10^9

#最大公約数
import fractions
import math

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

A,B,C,D = map(int, input().split())
#A 以上 B 以下の整数…最大10^18個
#print([i for i in range(A,B+1)])
#print(B-A+1)
#print("B:",math.floor(B/C),math.floor(B/D),math.floor(B/(D*C)))
#print("A:",math.ceil(A/C),math.ceil(A/D),math.ceil(A/(D*C)))
#print("B-A+1:",math.floor(B/C)-math.ceil(A/C)+1,math.floor(B/D)-math.ceil(A/D)+1,math.floor(B/(lcm(C, D)))-math.ceil(A/lcm(C, D))+1)

print(B-A+1-((math.floor(B/C)-math.ceil(A/C)+1)+(math.floor(B/D)-math.ceil(A/D)+1)-(math.floor(B/(lcm(C, D)))-math.ceil(A/(lcm(C, D)))+1)))

Submission status: Wrong Answer

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

c_min = a + (c - a % c)
c_max = b - (b % c)
c_amount = (c_max - c_min) // c + 1

d_min = a + (d - a % d)
d_max = b - (b % d)
d_amount = (d_max - d_min) // d + 1

cd_min = a + (c*d - a % (c*d))
cd_max = b - (b % (c*d))
cd_amount = (cd_max - cd_min) // (c*d) + 1

print(amount - c_amount - d_amount + cd_amount)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
li=[]
for i in [a-1,b]:
    bc = i//c
    bd = i//d
    gc = c*d / gcd(c,d)
    cd = i//gc
    li.append(i-(bc+bd-cd))
print(int(li[1]-li[0]))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
li=[]
for i in [a-1,b]:
    bc = i//c
    bd = i//d
    gc = c*d / fractions.gcd(c,d)
    cd = i//gc
    li.append(i-(bc+bd-cd))
print(int(li[1]-li[0]))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
n = b - a + 1
import math
from fractions import gcd
def lcm(a, b):
  g = gcd(a, b)
  return g * (a//g) * (b//g)

def divisorcount(a, b, c):
  return math.floor(b / c) - math.ceil(a / c) + 1

print(n - divisorcount(a, b, c) - divisorcount(a, b, d) + divisorcount(a, b, lcm(c, d)))

Submission status: Wrong Answer

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

print(int((b-a+1)-(b//c+b//d-(a-1)//c-(a-1)//d)+(b//(c*d)-(a-1)//(c*d))))

Submission status: Wrong Answer

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

print(int((b-a+1)-(b//c+b//d-a//c-a//d)+(b//(c*d)-a//(c*d))))

Submission status: Wrong Answer

Solution code:
A,B,C,D =map(int,input().split())
c_i =  ((A+C-1)//C)
c_f = B//C
c_dis = c_f-c_i+1 if c_f-c_i >= 0 else 0

d_i = ((A+D-1)//D)
d_f = B//D
d_dis = d_f-d_i+1 if d_f-d_i>= 0 else 0

cd = C*D
cd_i = ((A+cd-1)//cd)
cd_f = B//cd
cd_dis = cd_f-cd_i+1 if cd_f-cd_i >= 0 else 0

ans = B-A+1 - c_dis - d_dis+ cd_dis
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
m = list(map(int,input().split()))
c=[]
c.append(m[2])
c.append(m[3])
f=fractions.gcd(m[3],m[2])
p=(m[3]*m[2]) / f
c.append(p)
         
a=[]
a.append(m[0])
a.append(m[1])

d=[]
for i in range(3):
    for j in range(2):
        d.append(a[j]//c[i])
        
x = m[0] - d[0]-d[2]+d[4]
y = m[1] - d[1]-d[3]+d[5]
print(int(y-x))

Submission status: Wrong Answer

Solution code:
import math

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


def lcm(x, y):
    if gcd(x, y) != 0:
        return x * y / gcd(x, y)
    return x * y


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


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Submission status: Wrong Answer

Solution code:
import math

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


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / (c * d))


print(cantdiv(b) - cantdiv(a - 1))

Submission status: Wrong Answer

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


def cantdiv(x):
    return x - (x // c) - (x // d) + (x // (c * d))


print(cantdiv(b) - cantdiv(a - 1))

Submission status: Wrong Answer

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

cnt = 0
div = c * d
am = a % div
bm = b % div

start = am
if am < bm:
    end = bm + 1
else:
    end = bm + div

u = end - start

cnt = u - (u//c) - (u//d) + (u//div)

print(cnt)

Submission status: Wrong Answer

Solution code:
import fractions
m = list(map(int,input().split()))
c=[]
c.append(m[2])
c.append(m[3])
f=fractions.gcd(m[3],m[2])
p=(m[3]*m[2]) / f
c.append(p)
         
a=[]
a.append(m[0])
a.append(m[1])

d=[]
for i in range(3):
    for j in range(2):
        d.append(a[j]/c[i])
        

x=  (d[1]//1) - (-(-d[0]//1)) +1
y=  (d[3]//1) - (-(-d[2]//1)) +1
z=  (d[5]//1) - (-(-d[4]//1)) +1
print(m[1]-m[0]+1-int(x+y-z))

Submission status: Wrong Answer

Solution code:
L = list(map(int, input().split()))

def gcd(x, y):
    r = x % y
    if r == 0:
        return y
    return gcd(y, r)

c = L[1] - L[0] + 1
# Cで割れる
d = L[1] // L[2] - (L[0] - 1) // L[2]
# Dで割れる
e = L[1] // L[3] - (L[0] - 1) // L[3]
# CでもDでも割れる
l = int((L[2] * L[3]) / gcd(L[2], L[3]))
f = L[1] // l
# f = L[1] // L[2] * L[0] // L[1] // L[2] - ((L[0] - 1) // L[2] + 1) * L[0] // L[1] // L[2]
c = c - d - e + f
print(c)

Submission status: Wrong Answer

Solution code:
L = list(map(int, input().split()))

def gcd(x, y):
    r = x % y
    if r == 0:
        return y
    return gcd(y, r)

c = L[1] - L[0] + 1
# Cで割れる
d = L[1] // L[2] - (L[0] - 1) // L[2]
# Dで割れる
e = L[1] // L[3] - (L[0] - 1) // L[3]
# CでもDでも割れる
f = L[1] // ((L[2] * L[3]) // gcd(L[2], L[3]))
# f = L[1] // L[2] * L[0] // L[1] // L[2] - ((L[0] - 1) // L[2] + 1) * L[0] // L[1] // L[2]
c = c - d - e + f
print(c)

Submission status: Wrong Answer

Solution code:
L = list(map(int, input().split()))

c = L[1] - L[0] + 1
# Cで割れる
d = L[1] // L[2] - (L[0] - 1) // L[2]
# Dで割れる
e = L[1] // L[3] - (L[0] - 1) // L[3]
# CでもDでも割れる
f = L[1] // L[2] * L[0] // L[1] // L[2] - ((L[0] - 1) // L[2] + 1) * L[0] // L[1] // L[2]
c = c - d - e + f + 1
print(c)

Submission status: Wrong Answer

Solution code:

a, b, c, d = map(int,input().split())
e = c*d
l = [c,d,e]
l2 = [0,0,0]
for i in range(0,3):
    if a%l[i] == 0:
        l2[i] = b//l[i] - a//l[i] +1
    else:
        l2[i] = b//l[i] - a//l[i]
print(b-a+1 -l2[0] -l2[1] + l2[2])

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a,b,c,d=map(int,input().split())
koubai=c*d/gcd(c,d)
def hantei(y):
  if a%y==0:
    return (b//y-a//y)+1
  else:
    return (b//y-(1+(a//y)))+1
print(int(b-a+1-(hantei(d)+hantei(c)-hantei(koubai))))

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
G = C * D / fractions.gcd(C, D)
print(int(B - A + 1- (B // C - (A - 1) // C) - (B // D - (A - 1) // D) + (B // G - (A - 1) // G)))

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
G = C * D / fractions.gcd(C, D)
print(B - A + 1- (B // C - (A - 1) // C) - (B // D - (A - 1) // D) + (B // G - (A - 1) // G))

Submission status: Wrong Answer

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

if (b - a) // c != 0:
    can_c = (b - a) // c + 1
elif a <= c <= b:
    can_c = 1
else:
    can_c = 0
if (b - a) // d != 0:
    can_d = (b - a) // d + 1
elif a <= d <= b:
    can_d = 1
else:
    can_d = 0
cd = c * d / fractions.gcd(c, d)
if (b - a) // cd != 0:
    can_cd = (b - a) // cd + 1
elif a <= cd <= b:
    can_cd = 1
else:
    can_cd = 0

ans = int((b - a + 1) - can_c - can_d + can_cd)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=(int(x) for x in input().split(" "))
def nb_divisers(n,m):
    return n//m
def nb_d_btw(f,g,n):
    if f%n==0:
        print(nb_divisers(g,n)-nb_divisers(f,n)+1)
        return nb_divisers(g,n)-nb_divisers(f,n)+1
    else:
        print(nb_divisers(g,n)-nb_divisers(f,n))
        return nb_divisers(g,n)-nb_divisers(f,n)
def nb_notdivisers_f(a,b,c,d):
    e=int(c*d/fractions.gcd(c,d))
    return b-a+1-(nb_d_btw(a,b,c)+nb_d_btw(a,b,d)-nb_d_btw(a,b,e))
print(nb_notdivisers_f(A,B,C,D))

Submission status: Wrong Answer

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

max_cnt = b - a + 1
# cとdの最小公倍数
cd = int((c*d)/fractions.gcd(c, d))
multi_c = max_cnt // c
if (a % c) + (max_cnt % c) > c:
    multi_c += 1
multi_d = max_cnt // d
if (a % d) + (max_cnt % d) > d:
    multi_d += 1
multi_cd = max_cnt // cd
if (a & cd) + (max_cnt % cd) > cd:
    multi_cd += 1

count = max_cnt - multi_c - multi_d + multi_cd
print(count)

Submission status: Wrong Answer

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

max_cnt = b - a + 1
# cとdの最小公倍数
cd = int((c*d)/fractions.gcd(c, d))
multi_c = max_cnt // c
print(max_cnt)
if (a % c) + (max_cnt % c) > c:
    multi_c += 1
print(multi_c)
multi_d = max_cnt // d
if (a % d) + (max_cnt % d) > d:
    multi_d += 1
print(multi_d)
multi_cd = max_cnt // cd
if (a & cd) + (max_cnt % cd) > cd:
    multi_cd += 1
print(multi_cd)

count = max_cnt - multi_c - multi_d + multi_cd
print(count)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int, input().split())
f=C
g=D
while f%g!=0:
  f,g=[g, f%g]
l=C*D//g
m=B//l
n=A//l
print(B-(B//C)-(B//D)+m-(A-1-((A-1)//C)-((A-1)//D)+n))

Submission status: Wrong Answer

Solution code:
import fractions

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

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

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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

print(B - A - (B - A) // C - (B - A) // D + (B - A) // lcm)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

print(B - A - (B - A) // C - (B - A) // D + (B - A) // lcm)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
l = c * d
ans = 0
count = 0
if b - a >= l:
  for i in range(a, a+l+1):
    if i % c != 0 and i % d != 0:
      count += 1
  ans = count * ((b - a + 1) // l) + ((b - a + 1) % l)
else:
  for i in range(a, b+1):
    if i % c != 0 and i % d != 0:
      count += 1
  ans += count
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = [int(i) for i in input().split()]
e = b - a + 1
lcm = c*d//fractions.gcd(c,d)
bc = b//c
bd = b//d
ac = (a-1)//c
ad = (a-1)//d
bcd = b//lcm
acd = a//lcm
f = (bc + bd - bcd) - (ac+ ad -acd)
print(e-f)

Submission status: Wrong Answer

Solution code:
import math
while True:
    try:
        A, B, C, D = map(int, input().split())
        lcm = C * D // math.gcd(C, D)
        
        if A%C == 0:
            A1 = A//C*C
        else:
            A1 = (A//C + 1)*C
            
        if A%D == 0:
            A2 = A//D*D
        else:
            A2 = (A//D + 1)*D
            
        if A%lcm == 0:
            A3 = A//lcm*lcm
        else:
            A3 = (A//lcm + 1)*lcm
        """
        A1 = A//C*C if A%C == 0 else (A//C + 1)*C
        A2 = A//D*D if A%D == 0 else (A//D + 1)*D
        A3 = A//lcm*lcm if A%lcm == 0 else (A//lcm + 1)*lcm
        """
        ans = B - A + 1
        ans -= ((B-A1)//C + 1)
        ans -= ((B-A2)//D + 1)
        ans += ((B-A3)//lcm + 1)
        
        print(ans)
    except:
        break

Submission status: Wrong Answer

Solution code:
import math
while True:
    try:
        A, B, C, D = map(int, input().split())
        lcm = C * D // math.gcd(C, D)
        
        A1 = A//C*C if A%C == 0 else (A//C + 1)*C
        A2 = A//D*D if A%D == 0 else (A//D + 1)*D
        A3 = A//lcm*lcm if A%lcm == 0 else (A//lcm + 1)*lcm
        
        ans = B - A + 1
        ans -= ((B-A1)//C + 1)
        ans -= ((B-A2)//D + 1)
        ans += ((B-A3)//lcm + 1)
        
        print(ans)
    except:
        break

Submission status: Wrong Answer

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

import math

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

mul_c = b // c - (a - 1) // c + 1
mul_d = b // d - (a - 1) // d + 1

gcd_c_d = gcd(c, d)
lcm_c_d = gcd_c_d * (c // gcd_c_d) * (d // gcd_c_d)
mul_c_d = b // lcm_c_d - (a - 1) // lcm_c_d + 1

print(b - a + 1 - (mul_c + mul_d - mul_c_d))

Submission status: Wrong Answer

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

import math

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

mul_c = b // c - int(math.ceil(float(a) / c)) + 1
mul_d = b // d - int(math.ceil(float(a) / d)) + 1

gcd_c_d = gcd(c, d)
lcm_c_d = gcd_c_d * (c // gcd_c_d) * (d // gcd_c_d)
mul_c_d = b // lcm_c_d - int(math.ceil(float(a) / lcm_c_d)) + 1

print(b - a + 1 - (mul_c + mul_d - mul_c_d))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    if x%y == 0:
        return y

    else:
        return gcd(y,x%y)



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

if C < D:
    t = C
    C = D
    D = t

max_ky = gcd(C,D)

#最小公倍数
lcm_c = C/max_ky
lcm_d = D/max_ky
lcm = max_ky * lcm_c * lcm_d

count_b = B - (B//C + B//D - int(B//lcm))
count_a = A - (A//C + A//D - int(A//lcm))
if(A%C != 0 and A%D != 0):
    count_a -= 1
ans = count_b - count_a

print(ans)






#りゅうせいの解答1 実行時間超過
#A, B, C, D = map(int,input().split())
# ans = 0
# j = A
# while j <= B:
#     count = 0
#     if j%C:
#         count += 1
#     if j%D:
#         count += 1
#
#     if count == 2:
#         ans += 1
#
#     j+= 1
#
# print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    if x%y == 0:
        return y

    else:
        return gcd(y,x%y)



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

if C < D:
    t = C
    C = D
    D = t

max_ky = gcd(C,D)

#最小公倍数
lcm_c = C/max_ky
lcm_d = D/max_ky
lcm = max_ky * lcm_c * lcm_d

count_b = B - (B//C + B//D - int(B//lcm))
count_a = A - (A//C + A//D - int(A//lcm))
ans = count_b - count_a

print(ans)






#りゅうせいの解答1 実行時間超過
#A, B, C, D = map(int,input().split())
# ans = 0
# j = A
# while j <= B:
#     count = 0
#     if j%C:
#         count += 1
#     if j%D:
#         count += 1
#
#     if count == 2:
#         ans += 1
#
#     j+= 1
#
# print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
e = b-a+1
q = 0

p = e//c
l = e//d
m = e//(c*d)
n = p+l-m
tmp = e-n

print(tmp)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int, input().split())
diff=b-a+1
cnt=0
num_c = diff//c
num_d = diff//d
num_c_d = diff//((c*d)//fractions.gcd(c,d))
total = num_c + num_d - num_c_d
print(int((diff - total)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
lcm = int(c*d/gcd(c,d))
num_divb = int(b)-int(b/c)-int(b/d)+int(b/lcm)
num_diva = +(a-1)-int((a-1)/c)-int((a-1)/d)+int((a-1)/lcm)

print(int(int(num_divb)-int(num_diva)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
gcd_cd = c*d/gcd(c,d)
num_divb = int(b)-int(b/c)-int(b/d)+int(b/gcd_cd)
num_diva = +(a-1)-int((a-1)/c)-int((a-1)/d)+int((a-1)/gcd_cd)

print(int(int(num_divb)-int(num_diva)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
gcd_cd = c*d/gcd(c,d)
num_divb = int(b)-int(b/c)-int(b/d)+int(b/gcd_cd)
num_diva = +(a-1)-int((a-1)/c)-int((a-1)/d)+int((a-1)/gcd_cd)

print(int(num_divb)-int(num_diva))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a,b,c,d = map(int,input().split())
gcd_cd = c*d/gcd(c,d)
num_divb = int(b)-int(b/c)-int(b/d)+int(b/gcd_cd)
num_diva = -(a-1)+int((a-1)/c)+int((a-1)/d)-int((a-1)/gcd_cd)

print(int(num_divb)+int(num_diva))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x
A, B, C, D = (int(a) for a in input().split())
lcm = gcd(C, D)
a = B - A + 1
b = abs(B // C - (A - 1) // C)
c = abs(B // D - (A - 1) // D)
d = abs(B // (C * D) - (A - 1) // ((C * D) // lcm))
print(a - (b + c - d))

Submission status: Wrong Answer

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

def gcd(c,d):
	if(c==0):
		return d
	else:
		return gcd(d%c,c)
prod = C*D
lcm = prod//gcd(C,D)

A-=1

AC=int(A/C)
AD=int(A/D)
BC=int(B/C)
BD=int(B/D)
ACD=int(A/lcm)
BCD=int(B/lcm)

print(B-A-BC-BD+BCD+AC+AD-ACD)

Submission status: Wrong Answer

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

def gcd(c,d):
	if(c==0):
		return d
	else:
		return gcd(d%c,c)
prod = C*D
lcm = prod//gcd(C,D)

AC=int(A/C)
AD=int(A/D)
BC=int(B/C)
BD=int(B/D)
ACD=int(A/lcm)
BCD=int(B/lcm)


print(B-A+1-BC-BD+BCD+AC+AD-ACD)

Submission status: Wrong Answer

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

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

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

AC=int(A/C)
AD=int(A/D)
BC=int(B/C)
BD=int(B/D)
ACD=int(A/lcm(C,D))
BCD=int(B/lcm(C,D))
A_=AC+AD-ACD
B_=BC+BD-BCD

print(B-A+1-BC-BD+BCD+AC+AD-ACD)

Submission status: Wrong Answer

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

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

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

AC=int(A/C)
AD=int(A/D)
BC=int(B/C)
BD=int(B/D)
ACD=int(A/lcm(C,D))
BCD=int(B/lcm(C,D))
A_=AC+AD-ACD
B_=BC+BD-BCD

print(int((B-B_)-(A-A_)))

Submission status: Wrong Answer

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

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

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

AC=int(A/C)
AD=int(A/D)
BC=int(B/C)
BD=int(B/D)
ACD=int(A/lcm(C,D))
BCD=int(B/lcm(C,D))
A_=AC+AD-ACD
B_=BC+BD-BCD

print((B-B_)-(A-A_))

Submission status: Wrong Answer

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

lcm = C*D / fractions.gcd(C,D)
ans = int( B // C ) + int( B // D ) - int( B // lcm)
ans -= int( (A-1) // C) + int((A-1) // D)  - int( (A-1) // lcm)
print(int(B - A + 1 - ans))

Submission status: Wrong Answer

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

icm = C*D / fractions.gcd(C,D)
ans = B - int(B // C) - int(B // D)  + int(B // icm)
ans -= A - 1 - int( (A-1) // C) - int((A-1) // D)  + int((A-1) // icm)
print(int(ans))

Submission status: Wrong Answer

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

n_all = b - a + 1
n_c = round(n_all / c)
n_d = round(n_all / d)
n_lcm = round(n_all / lcm)

ans = int(n_all - (n_c + n_d - n_lcm))
print(ans)

Submission status: Wrong Answer

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

n_all = b - a
n_c = int(n_all / c)
n_d = int(n_all / d)
n_lcm = int(n_all / lcm)

ans = n_all - (n_c + n_d - n_lcm)
print(ans)

Submission status: Wrong Answer

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

icm = C*D / fractions.gcd(C,D)
ans = 0#(B - A + 1)
if A != B:
    if A % C == 0:
        ans += int(B // C - A // C) + 1
    else:
        ans += int(B // C - A // C)
    if A % D == 0:
        ans += int(B // D - A // D) + 1
    else:
        ans += int(B // D - A // D)

    if A % icm == 0:
        ans -= int(B // icm - A // icm) + 1
    else:
        ans -= int(B // icm - A // icm)
    print(int(ans))
else:
    if A % C == 0 or A % D == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

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

icm = C*D / fractions.gcd(C,D)
ans = (B - A + 1)
if A != B:
    if A % C == 0:
        ans -= int(B // C - A // C) + 1
    else:
        ans -= int(B // C - A // C)
    if A % D == 0:
        ans -= int(B // D - A // D) + 1
    else:
        ans -= int(B // D - A // D)

    if A % icm == 0:
        ans += int(B // icm - A // icm) + 1
    else:
        ans += int(B // icm - A // icm)
    print(int(ans))
else:
    if A % C == 0 or A % D == 0:
        print(0)
    else:
        print(1)

Submission status: Wrong Answer

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

icm = C*D / fractions.gcd(C,D)
ans = (B - A + 1)
if A != B:
    if A % C == 0:
        ans -= int(B // C - A // C) + 1
    else:
        ans -= int(B // C - A // C)
    if A % D == 0:
        ans -= int(B // D - A // D) + 1
    else:
        ans -= int(B // D - A // D)

    if A % icm == 0:
        ans += int(B // icm - A // icm) + 1
    else:
        ans += int(B // icm - A // icm)

else:
    if A % C == 0 or A % D == 0:
        print(0)
    else:
        print(1)
    print(int(ans))

Submission status: Wrong Answer

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

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

if A % icm == 0:
    ans += int(B // icm - A // icm) + 1
else:
    ans += int(B // icm - A // icm)

print(int(ans))

Submission status: Wrong Answer

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

icm = C*D / fractions.gcd(C,D)
ans = (B - A + 1)
if A % C == 0:
    ans -= (B // C - A // C) + 1
else:
    ans -= (B // C - A // C)
if A % D == 0:
    ans -= (B // D - A // D) + 1
else:
    ans -= (B // D - A // D)

if A % icm == 0:
    ans += (B // icm - A // icm) + 1
else:
    ans += (B // icm - A // icm)

print(int(ans))

Submission status: Wrong Answer

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

icm = C*D / fractions.gcd(C,D)
ans = (B - A + 1)
if A % C == 0:
    ans -= (B // C - A // C) - 1
else:
    ans -= (B // C - A // C)
if A % D == 0:
    ans -= (B // D - A // D) - 1
else:
    ans -= (B // D - A // D)

if A % icm == 0:
    ans += (B // icm - A // icm) - 1
else:
    ans += (B // icm - A // icm)

print(int(ans))

Submission status: Wrong Answer

Solution code:
W,H,x,y = map(int,input().split())

if W//2 == x and H//2 == y:
    ans = 1
else:
    ans = 0
print(W*H/2,ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=[int(i) for i in input().split()]
c1=b//c-a//c
if a%c==0:
    c1+=1
d1=b//d-a//d
if a%d==0:
    d1+=1
cd1=b//(c*d)-a//(c*d)
if a%(c*d)==0:
    cd1+=1
print(b-a+1-c1-d1+cd1)

Submission status: Wrong Answer

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

dc = (B//C) - ((A-1)//C)
dd = (B//D) - ((A-1)//D)
lcmCD = (C*D)/fractions.gcd(C, D)
dcd = int((B//lcmCD) - ((A-1)//lcmCD))

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

Submission status: Wrong Answer

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

dc = (B//C) - ((A-1)//C)
dd = (B//D) - ((A-1)//D)
lcmCD = (C*D)/fractions.gcd(C, D)
dcd = int((B//lcmCD) - ((A-1)//lcmCD))

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

Submission status: Wrong Answer

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

p = b//c - a//c
q = b//d - a//d
r = b*fractions.gcd(c,d)//(c*d) - a*fractions.gcd(c,d)//(c*d)
print(b-a+1-p-q+r)

Submission status: Wrong Answer

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

p = b//c - a//c
q = b//d - a//d
r = b*fractions.gcd(c,d)//(c*d)
print(b-a+1-p-q+r)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int, input().split())
p = (b-a) // c
q = (b-a) // d
r = (b-a) * fractions.gcd(c,d) // (c*d)
print(b-a-p-q+r)

Submission status: Wrong Answer

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

dc = math.floor(B/C) - math.floor((A-1)/C)
dd = math.floor(B/D) - math.floor((A-1)/D)
lcmCD = (C*D)/fractions.gcd(C, D)
dcd = math.floor(B/lcmCD) - math.floor((A-1)/lcmCD)

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

Submission status: Wrong Answer

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

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

a, b, c, d = (int(i) for i in input().split())

cd = lcm(c,d)
r = b-a+1

min_c = math.ceil(a/c)
max_c = b//c
min_d = math.ceil(a/d)
max_d = b//d
min_cd = math.ceil(a/cd)
max_cd = b//cd

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(r-c_num-d_num+cd_num)

Submission status: Wrong Answer

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

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

a, b, c, d = (int(i) for i in input().split())

cd = lcm(c,d)
r = b-a+1

min_c = math.ceil(a/c)
max_c = b//c
min_d = math.ceil(a/d)
max_d = b//d
min_cd = math.ceil(a/cd)
max_cd = b//cd

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(c_num)
print(d_num)
print(cd)

print(r-c_num-d_num+cd_num)

Submission status: Wrong Answer

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

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

a, b, c, d = (int(i) for i in input().split())

cd = lcm(c,d)
r = b-a+1

min_c = math.ceil(a/c)
max_c = math.floor(b/c)
min_d = math.ceil(a/d)
max_d = math.floor(b/d)
min_cd = math.ceil(a/cd)
max_cd = math.floor(b/cd)

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(r-c_num-d_num+cd_num)

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split(' ')))
counter = 0
counter += b//c - a//c
counter += b//d - a//d
counter -= b//(c*d) - a//(c*d)

print(int(b-a-counter))

Submission status: Wrong Answer

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

try:
    from math import gcd
except:
    from fractions import gcd
    
LCM = C * D / gcd(C,D)
    
Ans_B = B - (B//C + B//D - B//LCM)
Ans_A = A-1 - ((A-1)//C + (A-1)//D  - (A-1)//LCM) 
    
print(int(Ans_B - Ans_A))