Problem:


Score : 300 points

Problem Statement

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

Constraints

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

1\leq C,D\leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

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

Sample Input 1

4 9 2 3

Sample Output 1

2

5 and 7 satisfy the condition.

Sample Input 2

10 40 6 8

Sample Output 2

23

Sample Input 3

314159265358979323 846264338327950288 419716939 937510582

Sample Output 3

532105071133627368



Sample input:
4 9 2 3


Sample output:
2

Submission status: Wrong Answer

Solution code:
import math


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


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


A, B, C, D = list(map(int, input().split()))
a_c = math.ceil(A / C)
b_c = math.floor(B / C)

abc = b_c - a_c + 1

a_d = math.ceil(A / D)
b_d = math.floor(B / D)

abd = b_d - a_d + 1 if b_d - a_d + 1 > 0 else 0

a_cd = math.ceil(A / (lcm(C, D)))
b_cd = math.floor(B / (lcm(C, D)))
abcd = b_cd - a_cd + 1 if b_cd - a_cd + 1 > 0 else 0
print((B - A + 1) - abc - abd + abcd)

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=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]*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=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]*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:
a, b, c, d = map(int, input().split())

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

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

if c == 1 or d == 1:
    print(b - a + 1)
    exit()

if a == 1:
    div_a = 0
else:
    div_a = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)
div_b = b // c + b // d - b // lcm(c, d)

print(b - a + 1 - div_b + div_a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

if c == 1 or d == 1:
    print(b - a + 1)
    exit()

if a == 1:
    div_a = 0
else:
    div_a = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)
div_b = b // c + b // d - b // lcm(c, d)

print(b - a + 1 - div_b + div_a)

Submission status: Wrong Answer

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

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

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

if c == 1 or d == 1:
    print(b - a + 1)
    exit()

div_a = (a-1) // c + (a-1) // d - (a-1) // lcm(c, d)
div_b = b // c + b // d - b // lcm(c, d)

print(b - a + 1 - div_b + div_a)

Submission status: Wrong Answer

Solution code:
import math


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


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


A, B, C, D = list(map(int, input().split()))
a_c = math.ceil(A / C)
b_c = math.floor(B / C)

abc = b_c - a_c + 1

a_d = math.ceil(A / D)
b_d = math.floor(B / D)

abd = b_d - a_d + 1

a_cd = math.ceil(A / (lcm(C, D)))
b_cd = math.floor(B / (lcm(C, D)))
abcd = b_cd - a_cd + 1
print((B - A + 1) - abc - abd + abcd)

Submission status: Wrong Answer

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

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]*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:
A,B,C,D=map(int,input().split())

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 copy
import fractions

inp = input()
# inp = "314159265358979323 846264338327950288 419716939 937510582"
inp = inp.split(" ")
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
d = int(inp[3])

h = c * d / fractions.gcd(c, d)
e = int(b / c) - int((a-1) / c)
f = int(b / d) - int((a-1) / d)
g = int(b / h) - int((a-1) / h)

print((b-a+1)-(e+f-g))

Submission status: Wrong Answer

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

listsize=B-C-1

Q=0

for i in range(listsize):
    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:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return int(fractions.gcd(a, b))

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return int(aa + bb - ab)

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return int(fractions.gcd(a, b))

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return int(fractions.gcd(a, b))

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return int(fractions.gcd(a, b))

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return int(fractions.gcd(a, b))

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    # ans = calc(b, c, d) - calc(a - 1, c, d)
    # print(b - a + 1 - ans)
    num1 = b - calc(b,c,d)
    num2 = (a-1) - calc(a-1, c,d)
    print(num1-num2)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return int(fractions.gcd(a, b))

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    aa = (int(n/a))
    bb = (int(n/b))
    ab = (int(n/lcm(a,b)))
    return aa + bb - ab

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return fractions.gcd(a, b)

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

def calc(n, a, b):
    return int(n/a) + int(n/b) - int(n/lcm(a,b))

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    ans_a = a-1 - calc(a-1,c,d)
    ans_b = b - calc(b,c,d)
    # print(b - a + 1 - ans)
    print(ans_b - ans_a)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return fractions.gcd(a, b)

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    return int(n/a) + int(n/b) - int(n/lcm(a,b))

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
if C<D:
  c=C
  d=D
else:
  c=D
  d=C
while d%c!=0:
  c,d=d%c,c

e=B//C
f=(A-1)//C
g=B//D
h=(A-1)//D
i=B//(C*D/c)
j=(A-1)//(C*D/c)
ans=int(B-A-(e-f+g-h-i+j)+1)

print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
if C<D:
  c=C
  d=D
else:
  c=D
  d=C
while d%c!=0:
  c,d=d%c,c

out=int((B//C)-((A-1)//C)+(B//D)-((A-1)//D)-(B//(C*D/c))+((A-1)//(C*D/c)))
ans=B-A-out+1

print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
if C<D:
  c=C
  d=D
else:
  c=D
  d=C
while d%c!=0:
  c,d=d%c,c

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

print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
if C<D:
  c=C
  d=D
else:
  c=D
  d=C
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

c=gcd(c,d)

out=int(B//C-(A-1)//C+B//D-(A-1)//D-B//(C*D/c)+(A-1)//(C*D/c))
ans=B-A-out+1

print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
if C<D:
  c=C
  d=D
else:
  c=D
  d=C
while d%c!=0:
  c,d=d%c,c

out=int(B//C-(A-1)//C+B//D-(A-1)//D-B//(C*D/c)+(A-1)//(C*D/c))
ans=B-A-out+1

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return fractions.gcd(a, b)

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    return int(n/a) + int(n/b) - int(n/lcm(a,b))

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
c=C
d=D
while d%c!=0:
  c,d=d%c,c

out=int(B//C-(A-1)//C+B//D-(A-1)//D-B//(C*D/c)+(A-1)//(C*D/c))
ans=B-A-out+1

print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
c=C
d=D
while d%c!=0:
  c,d=d%c,c

out=int(B//C-A//C+B//D-A//D-B//(C*D/c)+A//(C*D/c))
ans=B-A-out
if A%C!=0 and A%D!=0:
  print(ans+1)
else:
  print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import fractions

def gcd(a, b):
    return fractions.gcd(a, b)

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

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)

def calc(n, a, b):
    return int(n/a) + int(n/b) - int(n/lcm(a,b))

if __name__ == '__main__':
    a, b, c, d = map(int, input().split())
    if (a == 1):
        ans = calc(b, c, d)
    else:
        ans = calc(b, c, d) - calc(a - 1, c, d)
    print(b - a + 1 - ans)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	if a < b:
		a,b = b,a
	while b:
		a, b = b, a % b
	return a
def lcm(a, b): 
	return (a*b)//gcd(a,b)

a,b,c,d = map(int,input().split())
a3 = b // c - a // c
b3 = b // d - a // d
if c < d:
	c,d = d,c
width = b - a + 1
c3 = b//lcm(c,d) - a//lcm(c,d)
print(int(width - a3 - b3 + c3))

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 = max // divisor1 - (min - 1) // divisor1;
divNum2 = max // divisor2 - (min - 1) // divisor2;
divNumLcm = max // lcmDivisors - (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 = max // divisor1 - (min + 1) // divisor1 + 1;
divNum2 = max // divisor2 - (min + 1) // divisor2 + 1;
divNumLcm = max // lcmDivisors - (min + 1) // lcmDivisors + 1;

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 = max // divisor1 - (min + 1) // divisor1 + 1;
divNum2 = max // divisor2 - (min + 1) // 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:
a, b, c, d = map(int, input().split())

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

import math

def count_div(x,y,z):
    dmin = math.ceil(x / z)
    dmax = math.floor(y / z)
    return dmax - dmin + 1

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a,b,c,d = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1
b1 = a//d
b2 = b//d
b3 = b2 - b1
if c < d:
	c,d = d,c
c3 = (c*d)/gcd(c,d)
width = b - a + 1
print(int(width - a3 - b3 + c3))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a,b,c,d = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1
b1 = a//d
b2 = b//d
b3 = b2 - b1
c3 = (c*d)/gcd(c,d)
width = b - a + 1
print(int(width - a3 - b3 + c3))

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a,b,c,d = map(int,input().split())
a1 = a//c
a2 = b//c
a3 = a2 - a1
b1 = a//d
b2 = b//d
b3 = b2 - b1
c3 = (c*d)/gcd(c,d)
width = b - a + 1
print(width - a3 - b3 + c3)

Submission status: Wrong Answer

Solution code:
#ABC131-C

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

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

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

def main():
  a,b,c,d=LI()

  c_i=b//c+(-a//c)+1
  d_i=b//d+(-a//d)+1
  cd_i=b//lcm(c,d)+(-a//lcm(c,d))+1

  x=b-a+1
  y=int(c_i+d_i-cd_i)

  return int(x-y)

print(main())

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd
a, b, c, d = list(map(int, input().split()))
lcm = c * d / gcd(c,d)
#Bの要素
c0 = math.floor(b/c)
d0 = math.floor(b/d)
lcm0 = math.floor(b/lcm)
#Aの要素
c1 = math.floor((a-1)/c)
d1 = math.floor((a-1)/d)
lcm1 = math.floor((a-1)/lcm)
ans = (b - c0 - d0 + lcm0) - (a - 1 - c1 - d1 + lcm1)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd
a, b, c, d = list(map(int, input().split()))
lcm = c * d / gcd(c,d)
#Bの要素
c0 = math.floor(b/c)
d0 = math.floor(b/d)
lcm0 = math.floor(b/lcm)
#Aの要素
c1 = math.floor((a-1)/c)
d1 = math.floor((a-1)/d)
lcm1 = math.floor((a-1)/lcm)
ans = (b - c0 - d0 + lcm0) - (a - 1 - c1 - d1 - lcm1)
print(ans)

Submission status: Wrong Answer

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

diff = abs(C-D)
lcm = C*D
for q in range(1, diff + 1):
  if diff < 2*q:
    break
  if diff % q == 0 and C % int(diff/q) == 0:
    lcm = C * D/diff * q
    break

num = []
for i in [C, D, lcm]:
  num.append(int(B/i) -int((A-1)/i) )
print(B- A + 1 -num[0]-num[1] +num[2])

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd
a, b, c, d = list(map(int, input().split()))
c0 = math.floor(b/c) - math.ceil(a/c) + 1
d0 = math.floor(b/d) - math.ceil(a/d) + 1
lcm = c * d / gcd(c,d)
lcm0 = math.floor(b/lcm) - math.ceil(a/lcm) + 1
ans = (b - a + 1) - c0 - d0 + lcm0
print(ans)

Submission status: Wrong Answer

Solution code:
A, B, C, D=map(int, input().split())
 
num = []
for i in [C, D, C*D]:
  num.append(int(B/i) -int(A/i) )
print(int(B- A -num[0]-num[1] +num[2]) )

Submission status: Wrong Answer

Solution code:
import math
import fractions

def f(a,b,c):
    if a<c and b<c:
        return 0
    l=b-a+1
    a=math.ceil(a/c)*c
    b=math.floor(b/c)*c
    return round(((b-a)/c))+1

a,b,c,d=list(map(int, input().split()))
lcm=round((c*d)/fractions.gcd(c,d))
_all=f(a,b,lcm)
_could_divide=f(a,b,c)+f(a,b,d)-_all
print(b-a+1-_could_divide)

Submission status: Wrong Answer

Solution code:
A, B, C, D=map(int, input().split())
 
num = []
for i in [C, D, C*D]:
  num.append(int(B/i) -int(A/i) )
print(B- A -num[0]-num[1] +num[2])

Submission status: Wrong Answer

Solution code:
import math
import fractions

def f(a,b,c):
    l=b-a+1
    a=math.ceil(a/c)*c
    b=math.floor(b/c)*c
    return round(((b-a)/c)+1)

a,b,c,d=list(map(int, input().split()))
lcm=round((c*d)/fractions.gcd(c,d))
_all=f(a,b,lcm)
_could_divide=f(a,b,c)+f(a,b,d)-_all
print(b-a+1-_could_divide)

Submission status: Wrong Answer

Solution code:
import math
import fractions

def f(a,b,c):
    l=b-a+1
    a=math.ceil(a/c)*c
    b=math.floor(b/c)*c
    return round(((b-a)/c)+1)

a,b,c,d=list(map(int, input().split()))
lcm=round((c*d)/fractions.gcd(c,d))
_all=f(a,b,lcm)
print(f(a,b,c),f(a,b,d),_all)
_could_divide=f(a,b,c)+f(a,b,d)-_all
print(b-a+1-_could_divide)

Submission status: Wrong Answer

Solution code:
import math
import fractions

def f(a,b,c):
    l=b-a+1
    a=math.ceil(a/c)*c
    b=math.floor(b/c)*c
    return int(((b-a)/c)+1)

a,b,c,d=list(map(int, input().split()))
lcm=(c*d)/fractions.gcd(c,d)
_all=f(a,b,lcm)
_could_divide=f(a,b,c)+f(a,b,d)-_all
print(b-a+1-_could_divide)

Submission status: Wrong Answer

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

num = []
for i in [C, D, C*D]:
  num.append(int(B/i) -int(A/i) )
print(B- A +1 -num[0]-num[1] +num[2])

Submission status: Wrong Answer

Solution code:
import fractions

def LCM(a,b):
    return a*b/fractions.gcd(a,b)

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print(int(result))

Submission status: Wrong Answer

Solution code:
i  = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

def gcd(n,m):
    x = min(n,m)
    y = max(n,m)
    while x != 0:
        x1 = x
        x = y%x
        y = x1
    return y

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

count = (b - b//c - b//d + b//l) - ((a-1) - (a-1)//c - (a-1)//d + (a-1)//l)
print(count)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n % m
  
  
l = (c*d)//n

s = (a-1)//c
t = (a-1)//d
u = (a-1)//l
x = b//c
y = b//d
z = b//l

B = b - x - y + z
A = a - 1 - s - t + u

print(B - A)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n % m
  
  
l = (c*d)//n

s = (a-1)//c
t = (a-1)//d
u = (a-1)//l
x = b//c
y = b//d
z = b//l

B = b - x - y + z
A = a - 1 - s - t + u

print(B - A + 1)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n % m
  
  
l = (c*d)/n

s = int((a-1)/c)
t = int((a-1)/d)
u = int((a-1)/l)
x = int(b/c)
y = int(b/d)
z = int(b/l)

B = b - x - y + z
A = a - 1 - s - t + u

print(B - A + 1)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n % m
  
  
l = (c*d)/n

s = int((a-1)/c)
t = int((a-1)/d)
u = int((a-1)/l)
x = int(b/c)
y = int(b/d)
z = int(b/l)

B = b - x - y + z
A = a - 1 - s - t + u

print(B - A)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n % m
  
  
g = n
l = int((c*d)/g)

s = int((a-1)/c)
t = int((a-1)/d)
u = int((a-1)/l)
x = int(b/c)
y = int(b/d)
z = int(b/l)

B = b - x - y + z
A = a - 1 - s - t + u

print(B - A)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n % m
  
  
g = n
l = (c*d)/g

s = (a-1)/c
t = (a-1)/d
u = (a-1)/l
x = b/c
y = b/d
z = b/l

B = b - x - y + z
A = a - 1 - s - t + u

print(B - A)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n % m
  
  
g = n
l = (c*d)/g

s = (a-1)/c
t = (a-1)/d
u = (a-1)/l
x = b/c
y = b/d
z = b/l

B = b - (x + y - z)
A = a - 1 - (s + t - u)

print(B - A)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n%m
  
  
g = n
l = (c*d)/g

s = (a-1)/c
t = (a-1)/d
u = (a-1)/l
x = b/c
y = b/d
z = b/l

B = b - (x + y - z)
A = a-1 -(s + t - u)

print(B - A)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n%m
  
  
g = n
l = (c*d)/g

s1 = (a-1)/c
t1 = (a-1)/d
u1 = (a-1)/l
x1 = b/c
y1 = b/d
z1 = b/l

A = (x1 + y1 - z1) - (s1 + t1 - u1)

print(b-a+1-A)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]

m = min(c,d)
n = max(c,d)

while m != 0:
  n = m
  m = n%m
  
  
g = n
l = (c*d)/g

s1 = (a-1)/c
t1 = (a-1)/d
u1 = (a-1)/l
x1 = b/c
y1 = b/d
z1 = b/l

A = (x1 + y1 - z1) - (s1 + t1 - u1)

print(A)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
c1=b//c
c2=(a-1)//c
c3=c1-c2
d1=b//d
d2=(a-1)//d
d3=d1-d2
cd1=b//(c*d)
cd2=(a-1)//(c*d)
cd3=cd1-cd2
print((b-a+1)-(c3+d3-cd3))

Submission status: Wrong Answer

Solution code:

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

x = B // C - (A-1)//C
y = B // D - (A-1) //D
import fractions as f
a = C*D // f.gcd(C,D)
z = B //a - A // a

print(B-A+1 -(x+y-z))

Submission status: Wrong Answer

Solution code:
import math

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


def solve():
    a, b, c, d = [int(i) for i in input().split()]

    ab = b - a + 1
    e = c * d / gcd(c, d)

    div = math.floor(ab / c) + math.floor(ab / d) - math.floor(ab / e)

    print(ab - div - 1)

    # 532105071133627368
    # 532105071133627369


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

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

nrofC = (B // C) - ((A-1) // C)
nrofD = (B // D) - ((A-1) // D)

cdlcm = C * D // gcd(C,D)
nrofCD = (B // cdlcm) - ((A-1) // cdlcm)

print((B-(A-1)) - nrofC - nrofD + nrofCD)

Submission status: Wrong Answer

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

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

def div(x,c,d):
    return x - x//c - x//d + x//lcm(c,d)


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

a = div(a,c,d)
b = div(b,c,d)
num = b-a

print(num)

Submission status: Wrong Answer

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

import fractions

def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        x, y = y, x % y
    return x
'''
def lcm(a,b):
	return a*b//gcd(a,b)
'''
a,b,c,d = [int(i) for i in input().split()]
'''
C = 0
D = 0
E = 0
'''
'''
for i in range(int(a / max(c,d,lcm(c,d))),b-a):
    print(i)
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
    if d * i >= a and d * i <= b and D == 0:
        D = d * i
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
    if C != 0 and D != 0 and E != 0:
        break
'''
'''
for i in range(int(a / lcm(c,d)) - 1,int(b / lcm(c,d))+2):
    if lcm(c,d) * i >= a and lcm(c,d) * i <= b and E == 0:
        E = lcm(c,d) * i
        break

for i in range(int(a / c) - 1,int(b / c)+2):
    if c * i >= a and c * i <= b and C == 0:
        C = c * i
        break

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

#print(b-a+1,c2,d2,e2)
'''
c1 = list(range(C,b+1,c))
d1 = list(range(D,b+1,d))
e1 = list(range(E,b+1,lcm(c,d)))
print(b-a+1,len(c1),len(d1),len(e1))

print(c1,d1,e1)

print(b-a+1-len(c1)-len(d1)+len(e1))
'''
print(int(b-a+1 - c2 - d2 + e2))

Submission status: Wrong Answer

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

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

def div(a,b,num):
    x = num/b
    sub = num%b
    if (a-1)/b != (a+sub)/b:
        x += 1
    return x

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

num = b-a+1
numc = int(div(a,c,num))
numd = int(div(a,d,num))
numl = int(div(a,lcm(c,d),num))
num = num - numc - numd + numl

print(num)

Submission status: Wrong Answer

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

nrofC = (B // C) - ((A-1) // C)
print(nrofC)
nrofD = (B // D) - ((A-1) // D)
print(nrofD)
nrofCD = (B // (C*D)) - ((A-1) // (C*D))
print(nrofCD)

print((B-(A-1)) - nrofC - nrofD + nrofCD)

Submission status: Wrong Answer

Solution code:
i = list(map(int,input().split()))
a = i[0]
b = i[1]
c = i[2]
d = i[3]
 

n1 = b/c
n2 = b/d
n3 = b - n1 - n2

m1 = (a-1)/c
m2 = (a-1)/d
m3 = (a-1) - m1 - m2

print(n3 -m3)

Submission status: Wrong Answer

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


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

def f(x, c, d):
    res = x
    res -= x//c
    res -= x//d
    res += lcm(c,d)
    return res

a, b, c, d = map(int, input().split())
a -= 1
ans = f(b,c,d) - f(a,c,d)
print(ans)

Submission status: Wrong Answer

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


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

def f(x, c, d):
    res = x
    res -= x/c
    res -= x/d
    res += lcm(c,d)
    return res

a, b, c, d = map(int, input().split())
a -= 1
ans = f(b,c,d) - f(a,c,d)
print(ans)