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:
#https://atcoder.jp/contests/abc131/tasks/abc131_c

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

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

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

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

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

print(c1,d1,e1)

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

Submission status: Wrong Answer

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

A,B,C,D = map(int, input().split())
A -= 1
E = lcm(C, D)
X = B//E - A//E
cc = B//C - A//C
dd = B//D - A//D
if max(C,D)%min(C,D) == 0:
    X += min(cc,dd)
if A+1==B==C or A+1==B==D:
    print(0)
else:
    print(B - A - cc - dd + X)

Submission status: Wrong Answer

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

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

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

ans = B-A+1
ans -= floor(B/C) - floor((A - 1)/C)
ans -= floor(B/D) - floor((A - 1)/D)
ans += floor(B/lcm(C,D)) - floor((A - 1)/lcm(C,D))

print(ans)

Submission status: Wrong Answer

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

x = (A-1) // C
xx = B // C
y = (A-1) // D
yy = B // D
E = C*D / gcd(C,D)
z = (A-1) // E
zz = B // E
tmp = xx-x + yy-y - (zz-z)
tmp = xx+yy-zz -x-y+z
print(int(B-A+1 - tmp))

Submission status: Wrong Answer

Solution code:
import fractions

ABCD = list(map(int, input().split()))

A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]


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

AB = B-A
count = 0

firstC = int(A-1/C)

firstD = int(A-1/D)


firstCD = int(A-1/lcm(C,D))


endC = int(B/C)
endD = int(B/D)
endCD = int(B/lcm(C,D))

thereC = endC - firstC
thereD = endD - firstD
thereCD = endCD - firstCD

NoP = thereC+thereD - thereCD
#
# print(thereC)
# print(thereD)
# print(thereCD)
# print(NoP)

print((B-A+1)-NoP)

Submission status: Wrong Answer

Solution code:
#C
from math import ceil, floor
from fractions import gcd
A,B,C,D = map(int, input().split())
X = int(C * D / gcd(C, D))
 
def retLR(A, B, num):
    #return A <= l*num < r*num <= B, length
    l = ceil(A/num)
    r = floor(B/num)
    length = r - l + 1
    return length
 
a1 = retLR(A,B,C)
a2 = retLR(A,B,D)
a3 = retLR(A,B,X)
 
subst = a1 + a2 - a3
ans = (B - A + 1) - subst
print(ans)

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
s = 0
start = a // c
end = b // c
if start * c < a:
    s += end - (start + 1) + 1
else:
    s += end - start + 1
if d % c != 0:
    start = a // d
    end = b // d
    if start * d < a:
        s += end - (start + 1) + 1
    else:
        s += end - start + 1
    def gcd(x, y):
        while y != 0:
            (x, y) = (y, x % y)
        return x
        return gcd
    last = c * d // gcd(c, d)
    start = a // last
    end = b // last
    if start * c < a:
        s -= end - (start + 1) + 1
    else:
        s -= end - start + 1
print((b - a + 1) - s)

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.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
if ans < 0:
    ans = 0
    
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int((lis[3]/gCD)*lis[2])
AmodC=lis[0]%lis[2]
if AmodC==0:
    AC=lis[0]
else:
    AC=lis[0]+(lis[2]-AmodC)
AmodD=lis[0]%lis[3]
if AmodD==0:
    AD=lis[0]
else:
    AD=lis[0]+(lis[3]-AmodD)
BC=lis[1]-lis[1]%lis[2]
BD=lis[1]-lis[1]%lis[3]
AmodCD=lis[0]%CD
if AmodCD==0:
    ACD=lis[0]
else:
    ACD=lis[0]+(CD-AmodCD)
BCD=lis[1]-lis[1]%CD
ABC=(BC-AC)/lis[2]+1
ABD=(BD-AD)/lis[3]+1
ABCD=(BCD-ACD)/CD+1
ans=lis[1]-lis[0]+1-int(ABC+ABD-ABCD)

print(ans)
#print(AC,AD,BC,BD,ACD,BCD,ABC,ABD,ABCD)

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())
CD=lcm(C, D)
 
def xc(x,C=C,D=D,CD=CD):
    return(x//C+x//D-x//(CD))
  
print(B-A+1-xc(B)-xc(A-1))

Submission status: Wrong Answer

Solution code:
s = input().split()
n = int(s[2])*int(s[3])
num = int(s[1])-int(s[0])
print((num*10)%n)

Submission status: Wrong Answer

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


f=math.ceil(a/c) 
g=math.floor(b/c) 
h=math.ceil(a/d) 
k=math.floor(b/d) 
l=math.ceil(a/e)
m=math.floor(b/e)

if e<a:
    print(b-a+1-(g-f+1+k-h+1))
else:
    print(b-a+1-(g-f+1+k-h+1-(m-l+1)))

Submission status: Wrong Answer

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



A,B,C,D = map(int,input().split())
CD = lcm(C, D)
#
# print("CD:",CD)
# print(" ===C====",math.ceil(A/C),math.floor(B/C))
# print(A/C,B/C)
# print(" ===D====",math.ceil(A/D),math.floor(B/D))
# print(A/D,B/D)
# print(" ===CD====",math.ceil(A/CD),math.floor(B/CD))
# print(A/CD,B/CD)


Cwari = math.floor(B/C) - math.floor((A-1)/C)
# print("Cwari:",Cwari)

Dwari = math.floor(B/D) - math.floor((A-1)/D)
# print("Dwari:",Dwari)


CDwari = math.floor(B/CD) - math.floor((A-1)/CD)
# print("CDwari:",CDwari)



print(B-A+1-(Cwari+Dwari-CDwari))

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = (int(i) for i in input().split())

duplicate = C * D // fractions.gcd(C, D)

cCnt = B// C
dCnt = B // D
duplicateCnt = B // duplicate

print(B - A - cCnt - dCnt + duplicateCnt)

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


ans_C = int(B/C) - int((A-1)/C)
ans_D = int(B/D) - int((A-1)/D)
CD = int((C*D) // gcd(C, D))
ans_CD = int(B/CD) - int((A-1)/CD)

print(B-A+1 -(ans_C + ans_D - ans_CD))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D//fractions.gcd(C,D)
if B-A>=C:
    if A%C==0 or B%C==0:
        L=(B-A)//C+1
    else:
        L=(B-A)//C
else:
    if A%C==0 or B%C==0:
        L=1
    elif A%C>B%C:
        L=1
    else:
        L=0
if B-A>=D:        
    if A%D==0 or B%D==0:
        M=(B-A)//D+1
    else:
        M=(B-A)//D
else:
    if A%D==0 or B%D==0:
        M=1
    elif A%D>B%D:
        M=1
    else:
        M=0       
if B-A>=E:
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if A%E==0 or B%E==0:
        N=1
    elif A%E>B%E :
        N=1
    else :
        N=0
X=B-A+1-L-M+N
print(X)

Submission status: Wrong Answer

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

_c = c
_d = d
if _c > _d :
	tmp = _d
	_d = _c
	_c = tmp
while _d % _c != 0:
	_d, _c = _c, _d % _c
cd = (c * d) // _c

_a = int(a/c) + int(a/d) - int(a/cd)
_b = int(b/c) + int(b/d) - int(b/cd)
ans = (b - a) - (_b - _a)

print(ans)

Submission status: Wrong Answer

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

A = a // c + a // d + a // lcm(c,d)
B = b // c + b // d + b // lcm(c,d)
print(A-B)

Submission status: Wrong Answer

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

cnt = 0
s = b - a + 1
cd = (c*d) // gcd(c,d)

m1 = int((a-1) / c)
m2 = int((b+1) / c)
cnt += (m2-m1)

m1 = int((a-1) / d)
m2 = int((b+1) / d)
cnt += (m2-m1)

m1 = int((a-1) / cd)
m2 = int((b+1) / cd)
cnt -= (m2-m1)

#print(cnt)
print(s - cnt)

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
A -= 1
tmp = fractions.gcd(C, D)
lcd = (C * D) // tmp
acnt1 = A // C
acnt2 = A // D
acnt3 = B // C
acnt4 = B // D
acnt5 = A // lcd
acnt6 = B // lcd
ans = B - A
atmp = acnt3 + acnt4 - acnt5 - acnt6 - acnt1 - acnt2
ans -= atmp
print(ans)

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


ans_C = int(B/C) - int((A-1)/C)
ans_D = int(B/D) - int((A-1)/D)
CD = int(C*D // gcd(C, D))
ans_CD = int(B/CD) - int((A-1)/CD)

print(B-A+1 -(ans_C + ans_D - ans_CD))

Submission status: Wrong Answer

Solution code:
s = input().split()
n = int(s[2])*int(s[3])
num = int(s[1])-int(s[0])
print((num*int(s[2]))%n)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def not_divided(x, A, B):
    if x > B:
        return 0
    if A == B:
        return 1 if A % x == 0 else 0
    lower = math.ceil(A / x)
    upper = math.floor(B / x)
    num = upper - lower + 1
    return num

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

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

    # not divided by C
    C_num = not_divided(C, A, B) 
    D_num = not_divided(D, A, B) 

    CD = C * D // gcd(C, D)
    CD_num = not_divided(CD, A, B)

    C_or_D_num = C_num + D_num - CD_num

    num = (B - A + 1) - C_or_D_num

    print(num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A , B , C , D = map(int, input().split())
hani = B - A + 1
Cdiv = B// C - (A + 1) // C
Ddiv = B// D - (A + 1) // D
def gcd(x, y):
    if x < y:
        tmp = x
        x = y
        y = tmp
    r = x % y   
    while r != 0:
        x = y
        y = r
        r = x % y
    return y
LCM = (C * D) // gcd(C, D)
LCMdiv = B // LCM - (A + 1) // LCM
ans = hani - Cdiv - Ddiv + LCMdiv
print(ans)

Submission status: Wrong Answer

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


def get_num(i):
    return int(b / i) - int((a-1) / i)


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


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


all_num = b - a + 1
c_num = get_num(c)
d_num = get_num(d)
lcm = lcm(c, d)
lcm_num = get_num(lcm) 

print(all_num - c_num - d_num + lcm_num)

Submission status: Wrong Answer

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

import math

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

E = int(C*D/gcd(C, D))
interval = B-A+1

n1 = math.ceil(A/C)
n2 = math.ceil(A/D)
n3 = math.ceil(A/E)

m1 = math.floor(B/C)
m2 = math.floor(B/D)
m3 = math.floor(B/E)

cnt_c = m1-n1+1
cnt_d = m2-n2+1
cnt_cd = m3-n3+1

print(interval-(cnt_c+cnt_d-cnt_cd))

Submission status: Wrong Answer

Solution code:
import fractions as f
a,b,c,d=map(int,input().split())
x=b-a+1
l=c*d//f.gcd(c,d)
i=b//c-a//c
j=b//d-a//d
k=b//l-a//l
if d%c==0 or c%d==0:
  print(x-max(i,j))
else:
  print(x-i-j+k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

count = int(i + j - k)

print(b-a+1-count)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def not_divided(x, A, B):
    if x > B:
        return 0
    if A == B:
        return 1 if A % x == 0 else 0
    lower = math.ceil(A / x)
    upper = math.floor(B / x)
    num = upper - lower + 1
    return num

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

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

    if C > D:
        C, D = D, C

    # not divided by C
    C_num = not_divided(C, A, B) 
    D_num = not_divided(D, A, B) 

    CD = C * D // gcd(C, D)
    CD_num = not_divided(CD, A, B)

    C_or_D_num = C_num + D_num - CD_num

    num = (B - A + 1) - C_or_D_num

    print(num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

A =A-1
CD = int(C * D / gcd(C, D))
num_A_C = int(A / C)
num_A_D = int(A / D)
num_A_CD = int(A / CD)
num_B_C = int(B / C)
num_B_D = int(B / D)
num_B_CD = int(B / CD)

num_B = B - (num_B_C + num_B_D - num_B_CD)
num_A = A - (num_A_C + num_A_D - num_A_CD)
ans = num_B - num_A
print(ans)

Submission status: Wrong Answer

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

def getAns(a, b, c):
  if a % c == 0:
    start = a
  else:
    start = a + c - (a % c)
    if start > b:
      return 0
    
  if b % c == 0:
    end = b
  else:
    end = b - c + (b % c)
    if end < a:
      return 0
    
  num_c = max((end - start) // c + 1, 0)
  return num_c

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

# cについて
num_c =getAns(a,b,c)
#print(num_c)

# dについて
num_d =getAns(a,b,d)
#print(num_d)

# cとdの公倍数について
cd = c / gcd(c,d)* d
num_cd = getAns(a,b,cd)
#print(num_cd)

print(b - a + 1 - (num_c + num_d - num_cd))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
p = 0
cntC = int(B / C) - int((A-1) / C)
cntD = int(B / D) - int((A-1) / D)

#a,bの最大公約数
def gcd(C, D):
    while D:
        C, D = D, C % D
    return C

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


CD = lcm(C, D)

cntCD = int(B / CD) - int((A-1) / CD)

# print(cntC, cntD, cntCD, CD)
calc = (B-A+1) - (cntC + cntD - cntCD)

print(calc)

Submission status: Wrong Answer

Solution code:
def get_num(i):
    return int(b / i) - int((a-1) / i)


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


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


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

all_num = b - a + 1
c_num = get_num(c)
d_num = get_num(d)
lcm = lcm(c, d)
lcm_num = get_num(lcm) 

print(all_num - c_num - d_num + lcm_num)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D//fractions.gcd(C,D)
if B-A>=C:
    if A%C==0 or B%C==0:
        L=(B-A)//C+1
    else:
        L=(B-A)//C
else:
    if A%C<B%C:
        L=1
    else:
        L=0
if B-A>=D:        
    if A%D==0 or B%D==0:
        M=(B-A)//D+1
    else:
        M=(B-A)//D
else:
    if A%D<B%D:
        M=1
    else:
        M=0       
if B-A>=E:
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if A%E<B%E :
        N=1
    else :
        N=0
X=B-A+1-L-M+N
print(X)

Submission status: Wrong Answer

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

s=c*d//fractions.gcd(c, d)
bk=0
ak=0
ans=0
bc=b//c
ac=a//c    
bd=b//d
ad=a//d
bsa=b//s
asa=a//s
bk=b-bc-bd+bsa
ak=a-ac-ad+asa
ans=bk-ak
if a%c!=0 or a%d!=0 or a%s!=0:
    ans+=1
elif b%c==0 or b%d==0 or b%s==0:
    ans-=1
else:
    ans=ans
print(ans)

Submission status: Wrong Answer

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

f=math.ceil(a/c) 
g=math.floor(b/c) 
h=math.ceil(a/d) 
k=math.floor(b/d) 
l=math.ceil(a/e)
m=math.floor(b/e)

if e<a:
    print(b-a+1-(g-f+1+k-h+1))
else:
    print(b-a+1-(g-f+1+k-h+1-(m-l+1)))

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/C) + 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:
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
A,B,C,D = map(int,input().split())
if A%C==0 and B%C==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(lcm(C,D)) == 0 and B%(lcm(C,D)) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)
if C == 1 or D == 1:
    print(0)
elif C == D:
    print((B-A+1) - C_div)
elif C%D==0 or D%C==0:
    if C > D:
        print((B-A+1) - D_div)
    else:
        print((B-A+1) - C_div)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
setAB=range(A,B+1)
setC=range(A,B+1,C)
setD=range(A,B+1,D)
setCD=range(A,B+1,C*D)
lenAB=len(setAB)
lenC=len(setC)
lenD=len(setD)
lenCD=len(setCD)
ans=lenAB-lenC-lenD+lenCD
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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



dd = int(b / d) - int(a / d)

i = 0
f = [c]
x = 10000000
k = [c, d]

while x != 0:
    x = max(k) % min(k)

    if x != 0:
        f.append(x)
    k.sort()
    k[1] = x
# Wprint(min(f))


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

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

Submission status: Wrong Answer

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

def solve(A: int, B: int, C: int, D: int):
    ci = int(B/C) - int((A-1)/C)
    di = int(B/D) - int((A-1)/D)
    l = C*D // fractions.gcd(C,D)
    xi = int(B/l) - int((A-1)/l)

    # print(ci,di,xi)
    print(B-A+1-ci-di+xi)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# ABC131C - Anti-Division
from fractions import gcd


def main():
    a, b, c, d = list(map(int, input().rstrip().split()))
    total, dif = b - a, b - a
    total -= dif // c + dif // d
    lcm = c * d // gcd(c, d)
    total += dif // lcm
    print(total)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input().split()
n = int(s[2])*int(s[3])
num = int(s[1])-int(s[0])
print(num%n)

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
import fractions
import math


#from numba import jit
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


def search(x, A, B):
    x_min = 0
    x_max = 0
    for i in range(1000000000):
        if (x * i > A):
            x_min = i
            break
    for i in range(1000000000):
        if (x * i > B):
            x_max = i
            break
    return x_max - x_min


def resolve():
    A, B, C, D = map(int, input().split())
    size = B - A + 1

    C_warikire = search(C, A, B)
    D_warikire = search(D, A, B)
    C_and_D_warikire = search(lcm(C, D), A, B)
    print(size - C_warikire - D_warikire + C_and_D_warikire)
    
resolve()

Submission status: Wrong Answer

Solution code:
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():
    A,B,C,D = [int(x) for x in input().split()]

    E = C*D

    Ct = 1
    if A == (A//C)*C:
        Ct = 0

    Cd = 0
    if B == (B//C)*C:
        Cd = 1

    Dt = 1
    if A == (A//D)*D:
        Dt = 0


    Dd = 0
    if B == (B//D)*D:
        Dd = 1

    Et = 1
    if A == (A//E)*E:
        Et = 0

    Ed = 0
    if B == (B//E)*E:
        Ed = 1
    Cwa = (B//C+Cd - (A//C+Ct))
    Dwa = (B//D+Dd - (A//D+Dt))
    CDw = (B//E+Ed - (A//E+Et))
    zen = B - A 

    print(zen + CDw - Cwa -Dwa)

    print(list(x*C for x in range(A//C, B//C+1)))
    #Dlist  = set(x*D for x in range(A//D, B//D+1))
    #ABlist = set(x for x in range(A,B+1))
    
    #print(len(Clist))

    #print(Clist)
    #print(Dlist)
    #print(Clist | Dlist)
    #print(ABlist)

    #anslist = ABlist - Clist

    #print(anslist)

    #count = len(anslist)
 

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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



dd = int(b / d) - int(a / d)

i = 0
f = [c]
x = 10000000
k = [c, d]

while x != 0:
    x = max(k) % min(k)

    if x != 0:
        f.append(x)
    k.sort()
    k[1] = x
# Wprint(min(f))


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

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

Submission status: Wrong Answer

Solution code:
# 2019/06/22
# AtCoder Beginner Contest 131 - C

import fractions
# Least Common Multiple
def lcm_fgf(a, b):
    return int(a * b / fractions.gcd(a, b))

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

clist = list()
dlist = list()
cdlist = list()

cd = lcm_fgf(c, d)

wkccnt = (b - a) // c
wkdcnt = (b - a + 1) // d
wkcdcnt = (b - a) // cd
rem1 = (b - a + 1) % c
rem2 = (b - a + 1) % d

print(wkccnt, wkdcnt, wkcdcnt)

candiv = wkccnt + wkdcnt - wkcdcnt
ans = (b - a + 1) - candiv - 1

# Output
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

divc = ceil((B + 1)/C) - ceil(A / C)
divd = ceil((B + 1)/D) - ceil(A / D)
dive = ceil((B + 1)/E) - ceil(A / E)

print(B + 1 - A - (divc + divd - dive))

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d=map(int,input().split())
yoso=b-a+1
kobai=c*d//fractions.gcd(c,d)
AC=c-(a%c)
if AC==c:
  AC=0
BC=b%c
AD=d-(a%d)
if AD==d:
  AD=0
BD=b%d
A_kobai=a%kobai
if A_kobai==kobai:
  A_kobai=0
B_kobai=b%kobai
C=0
if AC+BC>(yoso%c):
  C=yoso//c
else:
  C=(yoso//c)+1
D=0
if AD+BD>(yoso%d):
  D=yoso//d
else:
  D=(yoso//d)+1
CD=0
if A_kobai+B_kobai>(yoso%kobai):
  CD=yoso//kobai
else:
  CD=(yoso//kobai)+1
print(yoso+CD-C-D)

Submission status: Wrong Answer

Solution code:
A , B , C , D = map(int,input().split())
lst = []
list= [i for i in range(A,B) if i % C != 0]
for i in list:
    if  i % D != 0:
        lst.append(i)
print(len(lst))

Submission status: Wrong Answer

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

def amari(x,c,d):
  return x - (x//c) - (x//d)

cdgcd = fractions.gcd(c,d)

def lcm(c,d):
    return (c*d) //cdgcd

lcm = lcm(c,d)

# gcd(c,d)以下でc,dで割り切れないものの数
x0 =lcm - ( lcm/c + lcm/d -1)

# b以下の条件を満たす数
amari0 = b%lcm
sho0 = b//lcm
x1 = sho0 * x0 + amari(amari0,c,d)

# a未満
amari1 = (a-1)%lcm
sho1 = (a-1)//lcm
x2 = sho1 * x0 + amari(amari1,c,d)

print(int(x1-x2))

Submission status: Wrong Answer

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

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

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

lcm = lcm(C, D)

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

nc = int( (maxc - minc)/C ) + 1
nd = int( (maxd - mind)/D ) + 1 
nlcm = int( (maxlcm - minlcm)/lcm ) + 1

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

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

print(n)

Submission status: Wrong Answer

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



A,B,C,D = map(int,input().split())
CD = lcm(C, D)
# 
# print("CD:",CD)
# print(" ===C====",math.ceil(A/C),math.floor(B/C))
# print(A/C,B/C)
# print(" ===D====",math.ceil(A/D),math.floor(B/D))
# print(A/D,B/D)
# print(" ===CD====",math.ceil(A/CD),math.floor(B/CD))
# print(A/CD,B/CD)


Cwari = math.floor(B/C) - math.ceil(A/C) +1
# print("Cwari:",Cwari)

Dwari = math.floor(B/D) - math.ceil(A/D)+1
# print("Dwari:",Dwari)

if CD > B :
    CDwari = 0
    # print("CDwari:",CDwari)
elif CD == B:
    CDwari = 1
    # print("CDwari:",CDwari)
elif CD == A:
    CDwari = math.floor(B/CD) - math.ceil(A/CD) + 2
    # print("CDwari:",CDwari)
else:
    CDwari = math.floor(B/CD) - math.ceil(A/CD) + 1
    # print("CDwari:",CDwari)


print(B-A+1-(Cwari+Dwari-CDwari))

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int, input().split())
if B<C:
    if B<D:
        print(int(B-A+1))
    else:
        ist=(A-A%D)/D
        ien=(B-B%D)/D
        print(int(B-A+1-ien+ist-1))
elif B<D:
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    print(int(B-A+1-ien+ist-1))
else:
    ist,ien,jst,jen,kst,ken=1,1,1,1,1,0
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    jst=(A-A%D)/D
    jen=(B-B%D)/D
    ist=(A-A%(C*D))/(C*D)
    ien=(B-B%(C*D))/(C*D)
    print(int(B-A+1-ien+ist-1-jen+jst-1+ken-kst+1-2))

Submission status: Wrong Answer

Solution code:
import fractions

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

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

def num_of_mod0(mod):
    if A%mod == 0:
        start = A
    else:
        start = (int(A/mod) +1) * mod

    end = (int(B /mod)) * mod

    return (end - start) / mod +1
if C == 1 or D ==1:
    print(0)
else:
    ans =(B-A+1)-(num_of_mod0(C) + num_of_mod0(D)- num_of_mod0(lcm(C,D)))
    ans = int(ans)
    print(ans)

Submission status: Wrong Answer

Solution code:

#3

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

sum1 = b - (b//c + b//d -b//(c*d))
sum2 = a -( a//c + a//d -a//(c*d)) 

print(sum1 -sum2)

Submission status: Wrong Answer

Solution code:
numbers = input().split(' ')

a = int(numbers[0])	
b = int(numbers[1])
c = int(numbers[2])
d = int(numbers[3])

e = c * d
i = int(a / c) + 1
i2 = int(b / c)
j = int(a / d) + 1
j2 = int(a / d)
k = int(a / e) + 1
k2 = int(a / e)
count = i2 - i + j2 - j + k2 -k
print(b - a - count + 1)

Submission status: Wrong Answer

Solution code:
from sys import stdin

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

count = 0
for i in range(a,b+1):
    print(i)
    if(i%c==0 or i%d==0):
        count +=1
    if(i%(c*d)):
        count -=1
print(count)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D//fractions.gcd(C,D)
if B-A>=C:
    if A%C==0 or B%C==0:
        L=(B-A)//C+1
    else:
        L=(B-A)//C
else:
    if A%C>=B%C:
        L=1
    else:
        L=0
if B-A>=D:        
    if A%D==0 or B%D==0:
        M=(B-A)//D+1
    else:
        M=(B-A)//D
else:
    if A%D>=B%D:
        M=1
    else:
        M=0       
if B-A>=E:
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if A%E>=B%E :
        N=1
    else :
        N=0
X=B-A+1-L-M+N
print(X)