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:
        a, b = b, a
    return b if a%b == 0 else gcd(b, a%b)

def solve(a, b, c, d):
    ans = b - a + 1
    for p in [c, d]:
        ans -= b // p - (a-1) // p
    for p in [c*d//gcd(c,d)]:
        ans += b // p - (a-1) // p
    return ans

print(24, 18, gcd(24, 18))

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

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

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

divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = max - min + 1 - divNumTotal

print(int(ans))

Submission status: Wrong Answer

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

def solve(a, b, c, d):
    ans = b - a + 1
    for p in [c, d, -c*d//gcd(c,d)]:
        ans -= b // p - (a-1) // p
    return ans

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

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 = y
        y = mod
    return mod

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

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

divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = max - min + 1 - divNumTotal

print(int(ans))

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 = y
        y = mod
    return mod

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

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

divNumTotal = divNum1 + divNum2 - divNumLcm;
print(divNumTotal)
ans = max - min + 1 - divNumTotal

print(int(ans))

Submission status: Wrong Answer

Solution code:

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

cc = (b // c)- ((a - 1) // c)
dd = (b // d)- ((a - 1) // d)

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
# $print(min(f))


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

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

Submission status: Wrong Answer

Solution code:
import math

temp = input().split(" ")
min = int(temp[0])
max = int(temp[1])
divisor1 = int(temp[2])
divisor2 = int(temp[3])
divisors = [divisor1,divisor2] if divisor1 > divisor2 else [divisor2, divisor1]

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

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

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

divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = max - min + 1 - divNumTotal

print(int(ans))

Submission status: Wrong Answer

Solution code:
import math

temp = input().split(" ")
min = int(temp[0])
max = int(temp[1])
divisor1 = int(temp[2])
divisor2 = int(temp[3])
divisors = [divisor1,divisor2] if divisor1 > divisor2 else [divisor2, divisor1]

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

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

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

divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = max - min + 1 - divNumTotal

print(int(ans))

Submission status: Wrong Answer

Solution code:

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

cc = (b // c)- ((a - 1) // c)
dd = (b // d)- ((a - 1) // d)

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
# $print(min(f))


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

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

Submission status: Wrong Answer

Solution code:
import math

temp = input().split(" ")
mn = int(temp[0])
mx = 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(max(divisors[0], divisors[1]),min(divisors[0], divisors[1]));
lcmDivisors = divisor1 * divisor2 / gcdDivisors

divNum1 = math.floor(mx / divisor1) - math.ceil(mn / divisor1) + 1;
divNum2 = math.floor(mx / divisor2) - math.ceil(mn / divisor2) + 1;
divNumLcm = math.floor(mx / lcmDivisors) - math.ceil(mn / lcmDivisors) + 1;

divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = mx - mn + 1 - divNumTotal

print(int(ans))

Submission status: Wrong Answer

Solution code:

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

cc = (b // c)- ((a - 1) // c)
dd = (b // d )- ((a - 1) // d)

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
# $print(min(f))


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

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

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(max,min);
lcmDivisors = divisor1 * divisor2 / gcdDivisors

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

divNumTotal = divNum1 + divNum2 - divNumLcm;
ans = max - min + 1 - divNumTotal

print(int(ans))

Submission status: Wrong Answer

Solution code:

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

cc = b // c- (a - 1) // c
dd = b // d - (a - 1) // d

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
# $print(min(f))


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

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

Submission status: Wrong Answer

Solution code:

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

cc = math.floor(b // c) - math.floor((a - 1) // c)
dd = math.floor(b // d) - math.floor((a - 1) // d)

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
# $print(min(f))


cd =math.floor(b // (c * d / min(f))) - math.floor((a - 1) // (c * d / min(f)))

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

Submission status: Wrong Answer

Solution code:

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

cc = math.floor(b / c) - math.floor((a - 1) / c)
dd = math.floor(b / d) - math.floor((a - 1) / d)

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
# $print(min(f))


cd =math.floor(b / (c * d / min(f))) - math.floor((a - 1) / (c * d / min(f)))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

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

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

a, b, c, d = readmi()
t1 = b // c - (a - 1) // c
t2 = b // d - (a - 1) // d
l = lcm(c, d)
t3 = 0
if b >= l >= a:
    t3 = b // l - (a - 1) // l
ans = t1 + t2 - t3
print(b - (a - 1) - 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_ = int(math.floor(B/C)) - int(math.floor((A-1)/C))
D_ = int(math.floor(B/D)) - int(math.floor((A-1)/D))
C_and_D = int(math.floor(B/F)) - int(math.floor((A-1)/F))
print(count - int(C_ + D_ - C_and_D))

Submission status: Wrong Answer

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

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

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 = int(C*D/E)

C_ = math.floor(B/C) - math.ceil(A/C) + 1
D_ = math.floor(B/D) - math.ceil(A/D) + 1
C_and_D = math.floor(B/F) - math.ceil(A/F) + 1
print(count - (C_ + D_ - C_and_D))

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-1 - baisu(a-1,c) - baisu(a-1,d) + baisu(a-1,c*d/gcd(c,d))
to_b = b - baisu(b,c) - baisu(b,d) + baisu(b,c*d/gcd(c,d))

print(to_b - to_a)

Submission status: Wrong Answer

Solution code:
import fractions

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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    a -= 1
    cnt = b - a
    cnt -= int(b/c) - int(a/c)
    cnt -= int(b/d) - int(a/d)
    l = lcm(c, d)
    cnt += int(b/l) - int(a/l)
    print(cnt)

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b:
        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())

div_A_C = (A - 1) // C
div_A_D = (A - 1) // D
div_B_C = B // C
div_B_D = B // D

lcmCD = lcm(C, D)
div_A_lcmCD = A // lcmCD
div_B_lcmCD = B // lcmCD

ans = (B - A + 1) - (div_B_C + div_B_D) + (div_A_C + div_A_D) + (div_A_lcmCD + div_B_lcmCD)
print(ans)

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    a -= 1
    cnt = b - a
    cnt -= int(b/c) - int(a/c)
    cnt -= int(b/d) - int(a/d)
    l = lcm(c, d)
    cnt += int(b/l) - int(a/l)
    print(cnt)

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    cnt_ac, cnt_bc = int((a-1)/c), int(b/c)
    cnt_ad, cnt_bd = int((a-1)/d), int(b/d)
    cnt_acd, cnt_bcd = int((a-1)/lcm(c,d)), int(b/lcm(c,d))
    print((b-a+1) - ((cnt_bc-cnt_ac)+(cnt_bd-cnt_ad)-(cnt_bcd-cnt_acd)))

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

Submission status: Wrong Answer

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

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

def f(X, C, D):
    return int(X // C) + int(X // D) - int(X // ((C * D ) / gcd(C, D)))

ans = int((B - A + 1)) - int(f(B, C, D)) + int(f(A, C, D))

print(ans)

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    cnt_ac, cnt_bc = int((a-1)/c), int(b/c)
    cnt_ad, cnt_bd = int((a-1)/d), int(b/d)
    cnt_acd, cnt_bcd = int((a-1)/lcm(c,d)), int(b/lcm(c,d))
    print(max(0, (b-a+1) - ((cnt_bc-cnt_ac)+(cnt_bd-cnt_ad)-(cnt_bcd-cnt_acd))))

Submission status: Wrong Answer

Solution code:
s = input().split()
s = list(map(int,s))
A = s[0]
B = s[1]
C = s[2]
D = s[3]
if A%C > 0:
  i = B//C - A//C
else:
  i = B//C - A//C + 1
if A%D > 0:
  j = B//D - A//D
else:
  j = B//D - A//D + 1
p = C*D
if A%p > 0:
  k = B//p - A//p
else:
  k = B//p - A//p + 1
print(B-A+1-(i + j - k))

Submission status: Wrong Answer

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

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

def f(X, C, D):
    return int(X // C) + int(X // D) - int(X // ((C * D ) / gcd(C, D)))

ans = int((B - A + 1) - f(B, C, D) + f(A, C, D))

print(ans)

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    cnt_ac, cnt_bc = int((a-1)/c), int(b/c)
    cnt_ad, cnt_bd = int((a-1)/d), int(b/d)
    cnt_acd, cnt_bcd = int(a/lcm(c,d)), int(b/lcm(c,d))
    print(max(0, (b-a+1) - ((cnt_bc-cnt_ac)+(cnt_bd-cnt_ad)-(cnt_bcd-cnt_acd))))

Submission status: Wrong Answer

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


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


if __name__ == "__main__":
    a, b, c, d = map(int, input().split())
    cnt_ac, cnt_bc = int((a-1)/c), int(b/c)
    cnt_ad, cnt_bd = int((a-1)/d), int(b/d)
    cnt_acd, cnt_bcd = int(a/lcm(c,d)), int(b/lcm(c,d))
    print((b-a+1) - ((cnt_bc-cnt_ac)+(cnt_bd-cnt_ad)-(cnt_bcd-cnt_acd)))

Submission status: Wrong Answer

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

cc = []
dd = []
ccc = c
ddd = d
i = 2

while (ccc > i-1)  :
    if (ccc % i == 0) :
        cc.append(i)
        ccc = ccc / i
    else :
        i += 1

i=2
while (ddd > i-1)  :
    if (ddd % i == 0) :
        dd.append(i)
        ddd = ddd / i
    else :
        i += 1

cdz = 1
for cz in cc :
    for i in range(0,len(dd)) :   
        if (cz == dd[i]) :
            cdz = cdz * cz
            del dd[i]
            break

cd = c * d /cdz

wari = (int(b/c) + int(b/d) - int(b/int(cd)) - (int((a-1)/c) + int((a-1)/d) - int((a-1)/int(cd) )))

print(str(b - a - wari + 1))

Submission status: Wrong Answer

Solution code:
s = input().split()
s = list(map(int,s))
A = s[0]
B = s[1]
C = s[2]
D = s[3]
if A%C > 0:
  i = B//C - A//C
else:
  i = B//C - A//C + 1
if A%D > 0:
  j = B//D - A//D
else:
  j = B//D - A//D + 1
p = C*D
if A%p > 0:
  k = B//p - A//p
else:
  k = B//p - A//p + 1
print(i + j - k)

Submission status: Wrong Answer

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

import math
import copy

l = list(map(int,input().split()))
A = l[0]
B = l[1]
C = l[2]
D = l[3]

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

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

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
k = b-a+1
n = k - (k//c + k//d - k//(c*d))
if (k-1)%c==0 and a%c==0:
    n -= 1
if (k-1)%d==0 and a%d==0:
    n -= 1
if (k-1)%(c*d)==0 and a%(c*d)==0:
    n += 1
print(n)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
k = b-a+1
n = k - (k//c + k//d - k//(c*d))
if (k-1)%c==0 and a%c==0:
    n -= 1
if (k-1)%d==0 and a%d==0:
    n -= 1
if (k-1)%(c*d)==0 and a%(c*d)==0:
    n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = list(map(int, input().split()))
a -= 1
l = c*d/fractions.gcd(c,d)
b = b - b //c - b // d + b //l
a = a - a //c - a // d + a //l
print("{:.0f}".format(b-a))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
k = b-a+1
n = k - (k//c + k//d - k//(c*d))
if (k-1)%c==0 and a%c==0:
    n -= 1
if (k-1)%d==0 and a%d==0:
    n -= 1
print(n)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split())
k = b-a+1
n = k - (k//c + k//d - k//(c*d))
if (k-1)%c==0 and (a%c==0 or a%d==0):
    n -= 1
print(n)

Submission status: Wrong Answer

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

l = list(map(int,input().split()))
A = l[0]
B = l[1]
C = l[2]
D = l[3]

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

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

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = list(map(int, input().split()))
a -= 1
b = b - b //c - b // d + b // (c*d/fractions.gcd(c,d))
a = a - a //c - a // d + a // (c*d/fractions.gcd(c,d))
print("{:.0f}".format(b-a))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = list(map(int, input().split()))
b = b - b //c - b // d + b // (c*d/fractions.gcd(c,d))
a = (a-1) - (a-1) //c - (a-1) // d + (a-1) // (c*d/fractions.gcd(c,d))
print("{:.0f}".format(b-a))

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

a = int(B/C) - int((A-1)/C)
b = int(B/D) - int((A-1)/D)
c = int(B/lcm(C,D)) - int((A-1)/lcm(C, D))
count = B - (A - 1) - (a + b - c)

if count < 0:
    print(0)
else:
    print(count)

Submission status: Wrong Answer

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

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

a = int(B/C) - int((A-1)/C)
b = int(B/D) - int((A-1)/D)
c = int(B/lcm(C,D)) - int((A-1)/lcm(C, D))

print ( B - (A - 1) - (a + b - c))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(a,b): 
    if a == 0: 
        return b 
    return gcd(b % a, a) 
  
# Function to return LCM of two numbers 
def lcm(a,b): 
    return (a*b) / gcd(a,b) 

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

x1 = int(A//C)
x2 = int(A//D)
x3 = int(A//lcm(C,D))

y1 = int(B//C)
y2 = int(B//D)
y3 = int(B//lcm(C,D))

result = int(B-y1-y2+y3-(A-x1-x2+x3))
if(A%C!=0 and A%D!=0):
	result+=1
print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

# aとbの小公倍数を返す関数
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b) #再帰定義
    
#B以下のCの倍数の個数
div_c = int(B/C)
#B以下のDの倍数の個数
div_d = int(B/D)
#B以下のC,Dの倍数の個数
mygcd = gcd(C, D)#C,Dの最大公約数
l = int((C*D)/mygcd) #C,Dの最少公倍数
div_gcd = int(B/l)
myansB = B - div_c -div_d + div_gcd

#A以下のCの倍数の個数
div_cA = int((A-1)/C)
#B以下のDの倍数の個数
div_dA = int((A-1)/D)
#B以下のC,Dの倍数の個数
div_gcdl = int((A-1)/l)
myansA = A-1 - div_cA -div_dA + div_gcdl

print(myansB-myansA)

Submission status: Wrong Answer

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

# aとbの小公倍数を返す関数
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a % b) #再帰定義
    
#B以下のCの倍数の個数
div_c = int(B/C)
#B以下のDの倍数の個数
div_d = int(B/D)
#B以下のC,Dの倍数の個数
mygcd = gcd(C, D)#C,Dの最大公約数
l = int((C*D)/mygcd) #C,Dの最少公倍数
div_gcd = int(B/l)
myansB = B - div_c -div_d + div_gcd

#A以下のCの倍数の個数
div_cA = int((A-1)/C)
#B以下のDの倍数の個数
div_dA = int((A-1)/D)
#B以下のC,Dの倍数の個数
div_gcdl = int((A-1)/l)
myansA = A-1 - div_cA -div_dA + div_gcdl

print(myansB-myansA)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(x, y):  #最大公約数を求める
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義


if __name__ == "__main__":
    a, b, c, d =  map(int, input().split())
    
    
    
    bai_c = int(b // c)
    bai_d = int(b // d)

    l  = (c * d) / gcd(c, d)
    b_duplicated = int(b // l)

    bai_c2 = int((a - 1) // c)
    bai_d2 = int((a - 1) // d)
    
    l2 = (c * d) / gcd(c, d)
    a_duplicated = int((a - 1) // l2)
    
    ans = (b - (bai_c + bai_d - b_duplicated)) - ((a - 1) - (bai_c2 + bai_d2 - a_duplicated))
    print(int(ans))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):  #最大公約数を求める
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義


if __name__ == "__main__":
    a, b, c, d =  map(int, input().split())
    
    
    
    bai_c = b // c
    bai_d = b // d

    l  = (c * d) / gcd(c, d)
    b_duplicated = b // l

    bai_c2 = (a - 1) // c
    bai_d2 = (a - 1) // d
    
    l2 = (c * d) / gcd(c, d)
    a_duplicated = (a - 1) // l2
    
    ans = (b - (bai_c + bai_d - b_duplicated)) - ((a - 1) - (bai_c2 + bai_d2 - a_duplicated))
    print(int(ans))

Submission status: Wrong Answer

Solution code:
def gcd(a,b): 
    if a == 0: 
        return b 
    return gcd(b % a, a) 
  
# Function to return LCM of two numbers 
def lcm(a,b): 
    return (a*b) / gcd(a,b) 

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

A = A - 1
x1 = int(A//C)
x2 = int(A//D)
x3 = int(A//lcm(C,D))

y1 = int(B//C)
y2 = int(B//D)
y3 = int(B//lcm(C,D))

print(int(B-y1-y2+y3-(A-x1-x2+x3)))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):  #最大公約数を求める
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義


if __name__ == "__main__":
    a, b, c, d =  map(int, input().split())
    
    
    
    bai_c = int(b // c)
    bai_d = int(b // d)

    l  = (c * d) / gcd(c, d)
    b_duplicated = b // l

    bai_c2 = (a - 1) // c
    bai_d2 = (a - 1) // d
    
    l2 = int((c * d) / gcd(c, d))
    a_duplicated = int((a - 1) // l2)
    
    ans = (b - (bai_c + bai_d - b_duplicated)) - ((a - 1) - (bai_c2 + bai_d2 - a_duplicated))
    print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(x, y):  #最大公約数を求める
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義


if __name__ == "__main__":
    a, b, c, d =  map(int, input().split())
    
    
    
    bai_c = b // c
    bai_d = b // d

    l  = (c * d) / gcd(c, d)
    b_duplicated = b // l

    bai_c2 = (a - 1) // c
    bai_d2 = (a - 1) // d
    
    l2 = (c * d) / gcd(c, d)
    a_duplicated = (a - 1) // l2
    
    ans = (b - (bai_c + bai_d - b_duplicated)) - ((a - 1) - (bai_c2 + bai_d2 - a_duplicated))
    print(int(ans))

Submission status: Wrong Answer

Solution code:
def gcd(x, y):  #最大公約数を求める
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義


if __name__ == "__main__":
#    a, b, c, d = 314159265358979323, 846264338327950288, 419716939, 937510582
#    a, b, c, d = 10, 40, 6, 8
    a, b, c, d = 4, 9, 2, 3
    
    
    
    bai_c = b // c
    bai_d = b // d

    l  = (c * d) / gcd(c, d)
    b_duplicated = b // l

    bai_c2 = (a - 1) // c
    bai_d2 = (a - 1) // d
    
    l2 = (c * d) / gcd(c, d)
    a_duplicated = (a - 1) // l2
    
    ans = (b - (bai_c + bai_d - b_duplicated)) - ((a - 1) - (bai_c2 + bai_d2 - a_duplicated))
    print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

def Lcm(a,b):
    return a*b//fractions.gcd(a,b)
def Kosu(min,max,k):
    if(min%k==0):
        tyousei=1
    return max/k-(min-1)/k

min,max,a,b=map(int,input().split())
c=Lcm(a,b)
print(max+1-min-Kosu(min,max,a)-Kosu(min,max,b)+Kosu(min,max,c))

Submission status: Wrong Answer

Solution code:
import fractions

def Lcm(a,b):
    return int(a*b/fractions.gcd(a,b))
def Kosu(min,max,k):
    if(min%k==0):
        tyousei=1
    return int(max/k)-int((min-1)/k)

min,max,a,b=map(int,input().split())
c=Lcm(a,b)
print(max+1-min-Kosu(min,max,a)-Kosu(min,max,b)+Kosu(min,max,c))

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int, input().split()) 
count = 0 
for x in range(a, b+1):
  if x%c ==0 or x%d==0: 
    count += 1
print(count)

Submission status: Wrong Answer

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

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

lcm=C*D/gcd(C,D)
con1=B//C - (A-1)//C
con2=B//D - (A-1)//D
con3=B//lcm - (A-1)//lcm

print(B-(A-1)-(con1+con2-con3))

Submission status: Wrong Answer

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

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

lcm=C*D/gcd(C,D)
con1=B//C - A//C
con2=B//D - A//D
con3=B//lcm - A//lcm

print(B-(A-1)-(con1+con2-con3))

Submission status: Wrong Answer

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

if A%C==0 or A<C:
    Cst=A//C
else:
    Cst=A//C+1
Cen=B//C

if A%D==0 or A<D:
    Dst=A//D
else:
    Dst=A//D+1
Den=B//D
if C==D:
    andD=0
else:
    andD=Den-Dst+1

if A%(C*D)==0 or A<(C*D):
    CDst=A//(C*D)
else:
    CDst=A//(C*D)+1
CDen=B//(C*D)
if C*D>B:
    andnm=0
else:
    andnm=CDen-CDst+1
print(B-A+1-(Cen-Cst+1)-andD+andnm)

Submission status: Wrong Answer

Solution code:
import fractions as fr 
a,b,c,d=map(int,input().split())
lcm=(c*d)/fr.gcd(c,d)
cc=0
dd=0
cd=0
if a%c == 0:
  cc += b//c - a/c + 1
else:
  cc += b//c - a//c

if a%d == 0:
  dd += b//d - a/d + 1
else:
  dd += b//d - a//d

if a%lcm == 0:
  cd += b//lcm - a/lcm + 1
else:
  cd += b//lcm - a//lcm  

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

Submission status: Wrong Answer

Solution code:
import fractions as fr 
a,b,c,d=map(int,input().split())
lcm=(c*d)/fr.gcd(c,d)
cc=0
dd=0
cd=0
if a%c == 0:
  cc += b//c - a/c + 1
else:
  cc += b//c - a//c

if a%d == 0:
  dd += b//d - a/d + 1
else:
  dd += b//d - a//d

if a%lcm == 0:
  cd += b//lcm - a/lcm + 1
else:
  cd += b//lcm - a//lcm  

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

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

ans = B - A + 1

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

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

print(int(ans))

Submission status: Wrong Answer

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

if A%C==0 or A<C:
    Cst=A//C
else:
    Cst=A//C+1
Cen=B//C

if A%D==0 or A<D:
    Dst=A//D
else:
    Dst=A//D+1
Den=B//D
if A%(C*D)==0 or A<(C*D):
    CDst=A//(C*D)
else:
    CDst=A//(C*D)+1
CDen=B//(C*D)
print(B-A+1-(Cen-Cst+1)-(Den-Dst+1)+(CDen-CDst+1))