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:
def GCD(a,b):
  if a<b:
    tmp = a
    a = b
    b = tmp
 
  r = a % b
  while (r!=0): 
    a = b
    b = r
    r = a % b
  return b


A,B,C,D = map(int,input().split())
A = A - 1
upperC = int(B // C)
upperD = int(B // D)
lowerC = int(A // C)
lowerD = int(A // D)

numC = upperC - lowerC
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D / gcd
upperL = int(B / lcm)
lowerL = int(A / lcm)
numL = upperL - lowerL

print(str(B - A - (numC + numD - numL)))

Submission status: Wrong Answer

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


A,B,C,D = map(int,input().split())
A = A - 1
upperC = int(B / C)
upperD = int(B / D)
lowerC = int(A / C)
lowerD = int(A / D)

numC = upperC - lowerC
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D / gcd
upperL = int(B / lcm)
lowerL = int(A / lcm)
numL = upperL - lowerL

print(str(B - A - (numC + numD - numL)))

Submission status: Wrong Answer

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


A,B,C,D = map(int,input().split())
A = A - 1
upperC = int(B / C)
upperD = int(B / D)
lowerC = int(A / C)
lowerD = int(A / D)

numC = upperC - lowerC + 1
numD = upperD - lowerD + 1

gcd = GCD(C,D)

lcm = C * D / gcd
upperL = int(B / lcm)
lowerL = int(A / lcm)
numL = upperL - lowerL + 1

print(str(B - A + 1 - (numC + numD - numL)))

Submission status: Wrong Answer

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


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

upperC = int(B / C)
upperD = int(B / D)
lowerC = int(A / C)
lowerD = int(A / D)

numC = upperC - lowerC 
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D / gcd
upperL = int(B / lcm)
lowerL = int(A / lcm)
numL = upperL - lowerL

print(str(B - A- (numC + numD - numL)))

Submission status: Wrong Answer

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


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

upperC = int(B / C)
upperD = int(B / D)
lowerC = int(A / C)
lowerD = int(A / D)

numC = upperC - lowerC
numD = upperD - lowerD

gcd = GCD(C,D)

lcm = C * D / gcd
upperL = int(B / lcm)
lowerL = int(A / lcm)
numL = upperL - lowerL

print(str(B - A + 1 - (numC + numD - numL)))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
ans=b-a+1
ans-=b//c-(a-1)//c
ans-=b//d-(a-1)//d
e=c*d
ans+=b//e-(a-1)//e
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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


def dev_count(n,c,d):
    n -= n//c
    n -= n//d
    n += n//lcm(c,d)

    return n

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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


def dev_count(n,c,d):
    n -= n//c
    n -= n//d
    n += n//lcm(c,d)

    return n

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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


def dev_count(n,c,d):
    n -= n//c
    n -= n//d
    n += n//lcm(c,d)

    return n

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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


def dev_count(n,c,d):
    n -= n//c
    n -= n//d
    n += lcm(c,d)

    return n

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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


def dev_count(n,c,d):
    n -= n//c
    n -= n//d
    n += lcm(c,d)

    return n

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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


def dev_count(n,c,d):
    n -= n//c
    n -= n//d
    n += lcm(c,d)

    return n

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a, b, c, d = map(int, input().split())
lcm = c*d // gcd(c, d)
total = 0
# cの倍数の個数
if b//c!=a//c:
  total += b//c - a//c + (1 if a%c==0 else 0)

# dの倍数の個数
if b//d!=a//d:
  total += b//d - a//d + (1 if a%d==0 else 0)
  
# c*dの倍数の個数
if b//lcm!=a//lcm:
  total -= b//lcm - a//lcm + (1 if a%lcm==0 else 0)

print(b-a+1-total)

Submission status: Wrong Answer

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

import math
import fractions

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

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

# A〜Bのうち、C, Dで割り切れる数の個数を求める
C_yakusuu = math.floor(B / C) - math.ceil(A / C) + 1
D_yakusuu = math.floor(B / D) - math.ceil(A / D) + 1

# A〜Bのうち、CとDの公倍数の個数を求める
LCM = lcm(C, D)
LCM_yakusuu = math.floor(B / LCM) - math.ceil(A / LCM) + 1

print(B - A + 1 - (C_yakusuu + D_yakusuu - LCM_yakusuu))

Submission status: Wrong Answer

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

import math
import fractions

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

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

# A〜Bのうち、C, Dで割り切れる数の個数を求める
C_yakusuu = math.floor(B / C) - math.ceil(A / C) + 1
D_yakusuu = math.floor(B / D) - math.ceil(A / D) + 1

# A〜Bのうち、CとDの公倍数の個数を求める
LCM = lcm(C, D)
LCM_yakusuu = math.floor(B / LCM) - math.ceil(A / LCM) + 1

print(B - A + 1 - (C_yakusuu + D_yakusuu - LCM_yakusuu))

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

LCM = lcm(C, D)

x = B//C
y = B // D
z = B // LCM
ans = B-x-y+z

x = (A-1) // C
y = (A-1) // D
z = (A-1) // LCM

ans -= (A-1) - x - y + z

print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
if c > d:
    c, d = d, c
count = b - a
def baisuu(n):
    i1 = (a // n + bool(a % n))
    i2 = (b // n)
    return int(i2 - i1)

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

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

count = b - a + 1
def baisuu(n):
    return int((b - a) // n + bool(a % n or b % n))

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

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

count = b - a
def baisuu(n):
    i1 = (a // n + bool(a % n or b % n))
    i2 = (b // n)
    return int(i2 - i1)

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

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

count = b - a + 1
def baisuu(n):
    x = (b - a) // n
    return int(x + bool(a % n + b % n))

def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1
    return x / x1

print(count - baisuu(c) - baisuu(d) + baisuu(gcd(c, d)))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
 
count = b - a
def baisuu(n):
    i1 = (a // n )
    i2 = (b // n)
    return int(i2 - i1 + bool(a % n or b % n))
 
def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
 
count = b - a
def baisuu(n):
    i1 = (a // n + bool(a % n or b % n))
    i2 = (b // n)
    return int(i2 - i1)
 
def gcd(x1, x2):
    x = x1 * x2
    r = x2 % x1
    while r != 0:
        x2 = x1
        x1 = r
        r = x2 % x1

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
R = B-A
print(R - (int(R/C) + int(R/D) - int(R/(C*D))))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
print( sum([int(i%C==0 and i%D==0) for i in range(A, B+1)]) )

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

nums = b - a + 1
c_count = b // c - a // c + 1 if a % c == 0 else b // c - a // c
d_count = b // d - a // d + 1 if a % d == 0 else b // d - a // d
lcm = c * d // gcd(c, d)
lcm_count = b // lcm - a // lcm if a % lcm == 0 else b // lcm - a // lcm
print(nums - c_count - d_count + lcm_count)

Submission status: Wrong Answer

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

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

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

cd = lcm(c,d)

an = a-int(a/c)-int(a/d)+int(a/(cd))
bn = b-int(b/c)-int(b/d)+int(b/(cd))
print(bn-an)

Submission status: Wrong Answer

Solution code:
import fractions

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

div1 = A // C
div2 = A // D
div3 = (B-1) // C
div4 = (B-1) // D

X = C*D // int(fractions.gcd(C,D))
div5 = A // X
div6 = (B-1) // X

del_nums = (div3 + div4 - div6) - (div1 + div2 - div5)
result = B - A - del_nums
print(result)

Submission status: Wrong Answer

Solution code:
import fractions

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

div1 = A // C
div2 = A // D
div3 = (B-1) // C
div4 = (B-1) // D

X = C*D // int(fractions.gcd(C,D))
div5 = B // X

del_nums = (div3 + div4) - (div1 + div2) + div5
result = B - A - del_nums
print(result)

Submission status: Wrong Answer

Solution code:
import fractions

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

div1 = A // C
div2 = A // D
div3 = (B-1) // C
div4 = (B-1) // D

X = C*D // int(fractions.gcd(C,D))
div5 = A // X
div6 = B // X

del_nums = (div3 + div4 - div6) - (div1 + div2 - div5)
result = B - A - del_nums
print(result)

Submission status: Wrong Answer

Solution code:
import fractions

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

div1 = A // C
div2 = A // D
div3 = (B-1) // C
div4 = (B-1) // D

X = C*D // int(fractions.gcd(C,D))
div5 = A // X
div6 = B // X

result = (div3 + div4 - div6) - (div1 + div2 - div5)
print(result)

Submission status: Wrong Answer

Solution code:
# import fractions
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


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

Submission status: Wrong Answer

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

if (A%C == 0) or (B%C == 0):
    c = (B - A) - (B - A) // C - (B- A) // D
else:
    c = (B + 1 - A) - (B + 1- A) // C - (B + 1- A) // D

print(c)

Submission status: Wrong Answer

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

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

print(c)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if (B - A) % C == 0:
    c += 1

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

print(c)

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

a, b, c, d = map(lambda x: int(x), input().split())
min_x = math.floor(a/c)
max_x = math.floor(b/c)
min_y = math.floor(a/d)
max_y = math.floor(b/d)

gcd_a_b = gcd(a, b)
lcm_a_b = a * b // gcd_a_b


min_z = math.floor(a/lcm_a_b)
max_z = math.floor(b/lcm_a_b)

ans = ((b-a+1) - ((max_x-min_x) + (max_y-min_y) - (max_z-min_z)))
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
def f(B,n):
  return B//n
def gcd(a,b):
  if b==0:return a
  return gcd(b,a%b)
E = C*D/gcd(C,D)
print(B - f(B,C) - f(B,D) + f(B,E) - (A-1 - f(A-1,C) - f(A-1,D) + f(A-1,E)))

Submission status: Wrong Answer

Solution code:
import math
def lcm(a,b):
    A,B=a,b
    while b!=0:
        a,b=b,a%b
    return A*B//a
 
def count(a,b,c):
    return math.floor(b/c)-math.floor((a-1)/c)
 
A,B,C,D=map(int,input().split())
C_count = count(A,B,C)
D_count = count(A,B,D)
CD_count = count(A,B,lcm(C,D))
ans = B - (A - 1) - (C_count + D_count - CD_count)

Submission status: Wrong Answer

Solution code:
import math
def lcm(a,b):
    A,B=a,b
    while b!=0:
        a,b=b,a%b
    return A*B//a
 
def count(a,b,c):
    return math.floor(b/c)-math.floor((a-1)/c)
 
A,B,C,D=map(int,input().split())
C_count = count(A,B,C)
D_count = count(A,B,D)
CD_count = count(A,B,lcm(C,D))
ans = B - (A - 1) - (C_count + D_count - CD_count)
print("{}".format(ans))

Submission status: Wrong Answer

Solution code:
import math
def lcm(a,b):
    A,B=a,b
    while b!=0:
        a,b=b,a%b
    return A*B/a

def count(a,b,c):
    return b//c-(a-1)//c

A,B,C,D=map(int,input().split())
C_count = count(A,B,C)
D_count = count(A,B,D)
CD_count = count(A,B,lcm(C,D))
ans = B - (A - 1) - (C_count + D_count - CD_count)
print("{}".format(ans))

Submission status: Wrong Answer

Solution code:
import fractions

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

Submission status: Wrong Answer

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

x = 0
for i in range(a,b):
    if i % c != 0 and i % d != 0:
        x += 1
    else:
        pass
print(x)

Submission status: Wrong Answer

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

E = C * D

for i in range(C, 10 ** 9, C):
    if i % D == 0:
        E = i
        break

aC = (A - 1) // C
aD = (A - 1) // D
aE = (A - 1) // E
bC = B // C
bD = B // D
bE = B // E

aS = aC + aD - aE
bS = bC + bD - bE
sum = B - (A - 1) - (bS - aS)

print(sum)

Submission status: Wrong Answer

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


def gcd(x, y):
    z = max(x, y)
    for i in range(z, 0, -1):
        if x % i == 0 and y % i == 0:
            return i
            break


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


E = lcm(C, D)

A = A - 1

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

print(sum)

Submission status: Wrong Answer

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

E = C*D
for i in range(C, 10 ** 9, C):
    if i % D == 0:
        E = i
        break

aC = (A - 1) // C if A - 1 >= C else 0
aD = (A - 1) // D if A - 1 >= D else 0
aE = (A - 1) // E if A - 1 >= E else 0
bC = B // C if B >= C else 0
bD = B // D if B >= D else 0
bE = B // E if B >= E else 0

aS = aC + aD - aE
bS = bC + bD - bE
sum = B - (A - 1) - (bS - aS)

print(sum)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

if B//lcm==0:
    num_CD=0
else:
    num_CD=B//lcm-math.ceil(A/lcm)+1


if B//C==0:
    num_C=0
else:
    num_C=B//C-math.ceil(A/C)+1



if B//D==0:
    num_D=0
else:
    num_D=B//D-math.ceil(A/D)+1


ans=B-A+1-num_C-num_D+num_CD


print(int(ans))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
a, b, c, d = map(int, input().split())
cnt_c = (b // c) - ((a-1) // c)
cnt_d = (b // d) - ((a-1) // d)
cnt_cd = c*d/gcd(c, d)
cnt_cd = (b // (c*d)) - ((a-1) // (c*d))
cnt_all = b-a+1
print(cnt_all - (cnt_c + cnt_d - cnt_cd))

Submission status: Wrong Answer

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

def gcd(c, d):
    while d:
        c, d = d, c % d
    return c

lcm = c * d / gcd(c, d)
b_num = b - (b // c) - (b // d) + (b // lcm)
a_num = a - 1 - ((a - 1) // c) - ((a - 1) // d) + ((a - 1) // lcm)
print(int(b_num - a_num))

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

print(count)

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 or i% D == 0:
        continue
    else:   
        cnt += 1
print(cnt)

Submission status: Wrong Answer

Solution code:
import math

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

def gcd(C,D):
    if D==0:
        return C
    else:
        return gcd(D,C%D)

U=B-A+1
num1=B//C-(A-1)//C + B//D-(A+1)//D
x=C//gcd(C,D)*D
num2=B//x-(A-1)//x
print(U-num1+num2)

Submission status: Wrong Answer

Solution code:
import math
def lcm(a,b):
    A,B=a,b
    while b!=0:
        a,b=b,a%b
    return A*B/a

def count(a,b,c):
    return math.floor(b/c)-math.floor((a-1)/c)

A,B,C,D=map(int,input().split())
C_count = count(A,B,C)
D_count = count(A,B,D)
CD_count = count(A,B,lcm(C,D))
ans = B - (A - 1) - (C_count + D_count - CD_count)
print("{}".format(ans))

Submission status: Wrong Answer

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

def gcd(c, d):
    while d:
        c, d = d, c % d
    return c

lcm = c * d / gcd(c, d)
b_num = b - ((b // c) + (b // d) - (b // lcm))
a_num = a - 1 - (((a - 1) // c) + ((a - 1) // d) - ((a - 1) // lcm))
print(int(b_num - a_num))

Submission status: Wrong Answer

Solution code:
from math import floor
from fractions import gcd


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


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

LCM = lcm(C, D)

x = floor(B / C)
y = floor(B / D)
z = floor(B / LCM)
ans = B-x-y+z

x = floor((A-1) / C)
y = floor((A-1) / D)
z = floor((A-1) / LCM)

ans -= (A-1) - x - y + z

print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
# from math import gcd
from fractions import gcd


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


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

x = floor(B / C)
y = floor(B / D)
z = floor(B / LCM)
ans = B-x-y+z

x = floor((A-1) / C)
y = floor((A-1) / D)
z = floor((A - 1) / LCM)

ans -= (A - 1) - x - y + z

print(ans)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
from fractions import gcd


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


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

x = floor(B / C)
y = floor(B / D)
z = floor(B / LCM)
ans = B-x-y+z

x = floor((A-1) / C)
y = floor((A-1) / D)
z = floor((A - 1) / LCM)

ans -= (A-1)-x-y+z

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
from fractions import gcd


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


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

multiple_of_C = floor(B / C) - ceil(A / C) + 1
multiple_of_D = floor(B / D) - ceil(A / D) + 1
multiple_of_CtimesD = floor(B / LCM) - ceil(A / LCM) + 1

print((B-A+1)-multiple_of_C-multiple_of_D+multiple_of_CtimesD)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
if C>D:
  c=D
  d=C
else:
  c=C
  d=D
  
f=B//d
g=(A-1)//d
h=B//c
i=(A-1)//c
  
while c:
  c,d=d%c,c
j=C*D/d
k=B//j
l=(A-1)//j
print(int(B-A+1-(f-g+h-i-k+l)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(float,input().split())
count=0;x=[]
for i in range(int(b)):
    if i>=a:
        x.append(i)
for i in x:
    if not i%c==0 and not i%d==0:
        count+=1
print(count)

Submission status: Wrong Answer

Solution code:
nums = [int(x) for x in input().split(" ")]

num_range = nums[1] - nums[0]

res_list = []

for i in range(nums[0],nums[1]):
    nums.append(i)

count = 1
c_num = nums[2]
d_num = nums[3]
while c_num < nums[1] or d_num < nums[1]:
    c_num = c_num * count
    d_num = d_num * count
    #print(c_num)
    #print(d_num)
    count += 1
    if c_num not in res_list:
        if c_num >= nums[0] and c_num < nums[1]:
            res_list.append(c_num)
    if d_num not in res_list:
        if d_num >= nums[0] and d_num < nums[1]:
            res_list.append(d_num)

#print(res_list)
res_num = list(set(res_list))
print(num_range - len(res_num) -1)

Submission status: Wrong Answer

Solution code:
import sys


scan = sys.stdin.readline


def main():
  a, b, c, d = map(int, scan().rstrip().split())
  
  # swap
  if c > d:
    _ = c
    c = d
    d = _
  
  cd_mul_to_a = -(a-1) // ( c * d)
  cd_mul_to_b = -b // ( c * d)
  
  cd_mul_to_a += (a-1) // c
  cd_mul_to_b += b // c
  
  cd_mul_to_a += (a-1) // d
  cd_mul_to_b += b // d
  
  total = (b - a + 1) - (cd_mul_to_b - cd_mul_to_a)
  
  print(total)


main()

Submission status: Wrong Answer

Solution code:
import fractions

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

def multiple(A, B, C): #number of multiples of C between A and B
    return int((B+0.5)//C - (A-0.5)//C)

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

allnumbers = B-A+1

ans = allnumbers - (multiple(A,B,C) + multiple(A,B,D) - multiple(A,B,lcm(C,D)))

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
aa=a-1
aaa=aa-((aa//c)+(aa//d)-(aa//(c*d)))
bb=b-((b//c)+(b//d)-(b//(c*d)))
print(bb-aaa)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())
answer = 0
for i in range(A, B):
    if (i % C != 0) and (i % D != 0):
        answer += 1
print(answer)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
a = (B + 1 - A) // C
b = (B + 1 - A) // D
c = (B + 1 - A) // (C * D)
if A % C != 1 and A % D != 0 and B % C != 0 and B % D != 0:
    print((B + 1 - A) - (a + b - c) - 1)
else:
    print((B + 1 - A) - (a + b - c))

Submission status: Wrong Answer

Solution code:
def warikire(warare,waru):
    if warare%waru==0:
        return True
    return False

a,b,c,d=map(int,input().split())
cnt1=0
cnt2=0
cnt3=0
swi=0
ans1=0
ans2=0
ans3=0

for i in range(a,b+1):
    if swi==1:
        break
    if warikire(i,c):
        cnt1=i
        swi=1
swi=0
for i in range(a,b+1):
    if swi==1:
        break
    if warikire(i,d):
        cnt2=i
        swi=1
swi=0        
for i in range(a,b+1):
    if swi==1:
        break
    if warikire(i,c*d):
        cnt3=i
        swi=1

#print(cnt1,cnt2,cnt3)
ans1=(b-cnt1)//c
ans2=(b-cnt2)//d
ans3=(b-cnt3)//(c*d)
print(b-a-(ans1+ans2-ans3))

Submission status: Wrong Answer

Solution code:
def warikire(warare,waru):
    if warare%waru==0:
        return True
    return False

a,b,c,d=map(int,input().split())
cnt1=0
cnt2=0
cnt3=0
swi=0
ans1=0
ans2=0
ans3=0

for i in range(a,b+1):
    if swi==1:
        break
    if warikire(i,c):
        cnt1=i
        swi=1
swi=0
for i in range(a,b+1):
    if swi==1:
        break
    if warikire(i,d):
        cnt2=i
        swi=1
swi=0        
for i in range(a,b+1):
    if swi==1:
        break
    if warikire(i,c*d):
        cnt3=i
        swi=1

#print(cnt1,cnt2,cnt3)
ans1=(b-cnt1)//c
print(ans1)
ans2=(b-cnt2)//d
print(ans2)
ans3=(b-cnt3)//(c*d)
print(ans3)
print(b-a-(ans1+ans2-ans3))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
count = 0
for i in range(B - A):
    now = A + i
    if now % C != 0 and now % D != 0:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
c = ((B - A) + 1) // C
d = ((B - A) + 1) // D
e = ((B - A) + 1) // (C * D)
if A % 2 == 1:
    print(((B - A) + 1) - (c + d - e) - 1)
else:
    print(((B - A) + 1) - (c + d - e))

Submission status: Wrong Answer

Solution code:
import fractions

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

Submission status: Wrong Answer

Solution code:
import fractions

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
i = abs((a-1)//c-b//c)
j = abs((a-1)//d-b//d)
k = abs((a-1)//(c*d)-b//(c*d))
print(b-a+1-(i+j-k))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
Input = input()
a, b, c, d = Input.split()
a, b, c, d = int(a), int(b), int(c), int(d)
delta_c = (b-1)//c - a//c
delta_d = (b-1)//d - a//d
def lcm(x, y):
    return (x * y) // gcd(x, y)
cd = lcm(c, d)
delta_cd = (b-1)//cd - a//cd
num_cd = delta_c + delta_d - delta_cd
print( b-a+1 - num_cd, end='')

Submission status: Wrong Answer

Solution code:
a, b, c, d = list(map(int, input().split()))
def divNumCount(start, end, div):
    count = 0
    num = 0
    i = start
    while i <= end:
        if i % div == 0:
            i += div - 1
            count += 1
        i += 1
    return count
def euqlid(a,b):
    if a < b:
        temp = a
        a = b
        b = temp
    while(a % b != 0):
        temp = a % b
        a = b
        b = temp
    return b

C = 0
D = 0
CandD = 0
C = divNumCount(a, b, c)
D = divNumCount(a, b, d)
CandD = divNumCount(a, b, c * d / euqlid(c,d))
print("C => {} D => {} CandD => {}".format(C, D, CandD))
print(b - a + 1 - (C + D - CandD))

Submission status: Wrong Answer

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


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


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


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

Submission status: Wrong Answer

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


lcm = (c * d) // frac.gcd(c,d)
if a % lcm != 0:
    s = lcm - a % lcm
else:
    s = 0
e = b % lcm
m = ((b - e) - (a + s)) // lcm
modgcd = (b - a + 1) - (s + (lcm - 1) * m + e)

if a % c != 0:
    s = c - a % c
else:
    s = 0
e = b % c
m = ((b - e) - (a + s)) // c
modc = (b - a + 1)- (s + (c - 1) * m + e)

s = d - a % d
e = b % d
m = ((b - e) - (a + s)) // d
modd = (b - a + 1) - (s + (d - 1) * m + e)

print((b - a + 1)-(modc + modd - modgcd))

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1 #もともとのAとBの間の数
B=((a[1] + (a[2]-1))//a[2])-((a[0]-1 + (a[2]-1))//a[2]) #Bの中のCの倍数-Aの中のCの倍数
C=((a[1] + (a[3]-1))//a[3])-((a[0]-1 + (a[3]-1))//a[3]) #Bの中のDの倍数-Aの中のDの倍数
d=a[2]*a[3]/fractions.gcd(a[2],a[3]) #CとDの最小公倍数
D=((a[1]+d-1)//d)-((a[0]-1 + d - 1)//d) #Bの中の最小公倍数の倍数-Aの中の最小公倍数の倍数
print (int(A-B-C+D))

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1 #もともとのAとBの間の数
B=(a[1]//a[2])-((a[0]-1)//a[2]) #Bの中のCの倍数-Aの中のCの倍数
C=(a[1]//a[3])-((a[0]-1)//a[3]) #Bの中のDの倍数-Aの中のDの倍数
d=a[2]*a[3]/fractions.gcd(a[2],a[3]) #CとDの最小公倍数
D=(a[1]//d)-((a[0]-1)//d) #Bの中の最小公倍数の倍数-Aの中の最小公倍数の倍数
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1 #もともとのAとBの間の数
B=math.floor(a[1]/a[2])-math.floor((a[0]-1)/a[2]) #Bの中のCの倍数-Aの中のCの倍数
C=math.floor(a[1]/a[3])-math.floor((a[0]-1)/a[3]) #Bの中のDの倍数-Aの中のDの倍数
d=a[2]*a[3]/fractions.gcd(a[2],a[3]) #CとDの最小公倍数
D=math.floor(a[1]/d)-math.floor((a[0]-1)/d) #Bの中の最小公倍数の倍数-Aの中の最小公倍数の倍数
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=(a[1]//a[2])-((a[0]-1)//a[2])
C=(a[1]//a[3])-((a[0]-1)//a[3])
d=int(a[2]*a[3]/fractions.gcd(a[2],a[3]))
D=math.floor(a[1]/d)-math.floor((a[0]-1)/d)
print(A-B-C+D)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor((a[0]-1)/a[2])
C=math.floor(a[1]/a[3])-math.floor((a[0]-1)/a[3])
d=int(a[2]*a[3]/fractions.gcd(a[2],a[3]))
D=a[1]//d-(a[0]-1)//d
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor((a[0]-1)/a[2])
C=math.floor(a[1]/a[3])-math.floor((a[0]-1)/a[3])
d=int(a[2]*a[3]/fractions.gcd(a[2],a[3]))
D=a[1]/d-(a[0]-1)/d
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=int(math.floor(a[1]/a[2])-math.floor((a[0]-1)/a[2]))
C=int(math.floor(a[1]/a[3])-math.floor((a[0]-1)/a[3]))
d=int(a[2]*a[3]/fractions.gcd(a[2],a[3]))
D=int(math.floor(a[1]/d)-math.floor((a[0]-1)/d))
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor((a[0]-1)/a[2])
C=math.floor(a[1]/a[3])-math.floor((a[0]-1)/a[3])
d=a[2]//fractions.gcd(a[2],a[3]) *a[3]
D=math.floor(a[1]/d)-math.floor((a[0]-1)/d)
print(A-B-C+D)

Submission status: Wrong Answer

Solution code:
import math,fractions
a=list(map(int,input().split()))
A=a[1]-a[0]+1
B=math.floor(a[1]/a[2])-math.floor((a[0]-1)/a[2])
C=math.floor(a[1]/a[3])-math.floor((a[0]-1)/a[3])
d=int(a[2]*a[3]/fractions.gcd(a[2],a[3]))
D=math.floor(a[1]/d)-math.floor((a[0]-1)/d)
print(A-B-C+D)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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