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 fractions,math

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int((lis[3]/gCD)*lis[2])
lis[0]=lis[0]-1

print(lis)

AmodC=lis[0]%lis[2]
AC=lis[0]-AmodC
AmodD=lis[0]%lis[3]
AD=lis[0]-AmodD
AmodCD=lis[0]%CD
ACD=lis[0]-AmodCD

BmodC=lis[1]%lis[2]
BC=lis[1]-BmodC
BmodD=lis[1]%lis[3]
BD=lis[1]-BmodD
BmodCD=lis[1]%CD
BCD=lis[1]-BmodCD



ans=int((lis[1]-(BC/lis[2]+BD/lis[3]-BCD/CD))-(lis[0]-(AC/lis[2]+AD/lis[3]-ACD/CD)))

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

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;
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 fractions
import math

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

C_ = len(range(math.floor(A/C)*C,B+1,C))
D_ = len(range(math.floor(A/D)*D,B+1,D))
CD = (C*D) // fractions.gcd(C, D)
CD_ = len(range(math.floor(A/CD)*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)

Submission status: Wrong Answer

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

r = -1
a = -1
b = -1

if C > D:
    a = C
    b = D
else:
    a = D
    b = C

while True:
    r = a % b
    if r == 0:
        b = int(C*D/b)
        break
    a = b
    b = r

c = int(B / C)
d = int(B / D)
cd = int(B/b)

ans = (B-c-d+cd)

c = int((A-1) / C)
d = int((A-1) / D)
cd = int((A-1) / b)

ans = ans - (A-1-c-d+cd)
print(ans)

Submission status: Wrong Answer

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

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

hoge = input().split()
a = int(hoge[0])
b = int(hoge[1])
c = int(hoge[2])
d = int(hoge[3])

l = lcm(c, d)

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

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

C_ = len(range(int(math.ceil(A/C))*C,B+1,C))
D_ = len(range(int(math.ceil(A/D))*D,B+1,D))
CD = (C*D) // fractions.gcd(C, D)
CD_ = len(range(int(math.ceil(A/CD))*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)

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

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

def func(x):
    return x - (int(x/C) + int(x/D) - int(x/E))

print(func(B) - func(A-1))

Submission status: Wrong Answer

Solution code:
import fractions,math

lis=list(map(int,input().split()))
gCD=fractions.gcd(lis[2],lis[3])
CD=int((lis[3]/gCD)*lis[2])
lis[0]=lis[0]-1

print(lis)

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)
AmodCD=lis[0]%CD
if AmodCD==0:
    ACD=lis[0]
else:
    ACD=lis[0]+(CD-AmodCD)

BmodC=lis[1]%lis[2]
if BmodC==0:
    BC=lis[1]
else:
    BC=lis[1]-BmodC
BmodD=lis[1]%lis[3]
if BmodD==0:
    BD=lis[1]
else:
    BD=lis[1]-BmodD
BmodCD=lis[1]%CD
if BmodCD==0:
    BCD=lis[1]
else:
    BCD=lis[1]-BmodCD



ans=int((lis[1]-(BC/lis[2]+BD/lis[3]-BCD/CD))-(lis[0]-(AC/lis[2]+AD/lis[3]-ACD/CD)))

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

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

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

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

n = math.floor(A-1 / C)
m = math.floor(B / C)
count_div += m - n

l = math.floor(A-1 / D)
k = math.floor(B / D)
count_div += k - l

j = math.floor(A-1 / lcm(C, D))
i = math.floor(B / lcm(C, D))
count_div -= i - j

print(B - A + 1 - count_div)

Submission status: Wrong Answer

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

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

hoge = input().split()
a = int(hoge[0])
b = int(hoge[1])
c = int(hoge[2])
d = int(hoge[3])

l = lcm(c, d)

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

Submission status: Wrong Answer

Solution code:
import math
def hcf(a,b):
	if(a==0):
		return b
	if(b==0):
		return a
	return hcf(b,a%b)
a,b,c,d = list(map(int,input().split()))
cka = math.floor(b/c) - math.ceil(a/c) + 1
dka = math.floor(b/d) - math.ceil(a/d) + 1
lcm = (c*d)//(hcf(c, d))
dcka = math.floor(b/(lcm)) - math.ceil(a/(lcm)) + 1
print(b-a+1-cka-dka+dcka)

Submission status: Wrong Answer

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

r = -1
a = -1
b = -1

if C > D:
    a = C
    b = D
else:
    a = D
    b = C

while True:
    r = a % b
    if r == 0:
        b = int(C*D/b)
        break
    a = b
    b = r

c = int(B / C)
d = int(B / D)
cd = int(B/b)

ans = (B-c-d+cd)

c = int((A-1) / C)
d = int((A-1) / D)
cd = int((A-1) / b)

print(ans - (A-1-c-d+cd))

Submission status: Wrong Answer

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

#a~bでnで割り切れるものの数
def func(a, b, n):
    answer = (int(b/n) - int((a-1)/n))
    return answer

def func_test(a,b,n):
    return b//n - (a-1)//n

lcm = int((c * d) / fractions.gcd(c, d))

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

Submission status: Wrong Answer

Solution code:
import math
def hcf(a,b):
	if(a==0):
		return b
	# if(a==0):
	# 	return b
	return hcf(b%a,a)
a,b,c,d = list(map(int,input().split()))
cka = math.floor(b/c) - math.ceil(a/c) + 1
dka = math.floor(b/d) - math.ceil(a/d) + 1
lcm = (c*d)//(hcf(c, d))
# print("lcm",lcm)
dcka = math.floor(b/(lcm)) - math.ceil(a/(lcm)) + 1
# print(cka,dka,dcka)
print(b-a+1-cka-dka+dcka)

Submission status: Wrong Answer

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

if c == 1 or d == 1:
    print(0)
elif a == b:
    if a%c == 0 or a%d == 0:
        print(0)
    else:
        print(1)
else:
    an1 = int(b/c)
    an2 = int((a-1)/c)
    an3 = int(b/d)
    an4 = int((a-1)/d) 
    gcd = round(c * d / gcd(c, d))
    an5 = int(b/gcd)
    an6 = int((a-1)/gcd)
    if c == d:
        an = an1-an2
    else:
        an = an1-an2 + an3-an4 -(an5-an6)
    print((b-a+1)-an)

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
inputs = sys.stdin.readlines()
a, b, c, d = [int(x) for x in inputs[0].split(' ')]
e = c * d // gcd(c, d) # lcm(c, d)

_c = b // c - a // c
_d = b // d - a // d
_e = b // e - a // e

print(b+1 - a - _c - _d + _e)

Submission status: Wrong Answer

Solution code:
import math

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


cc = int(b / c) - int((a-1) / c)
dd = int(b / d) - int((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 = int(b / (c * d/min(f) )) - int((a-1) / (c * d/min(f) ))

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

Submission status: Wrong Answer

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

def gcd(a,b):
    r = divmod(a,b)[1]
    if r == 0:
        return int(b)
    else:
        return gcd(b,r)
    
l_c = int((A+C-1)/C)
u_c = B//C
n_c = u_c - l_c + 1 
l_d = int((A+D-1)/D)
u_d = B//D
n_d = u_d - l_d + 1
CD = C*D // gcd(C,D)
l_cd = int((A+CD-1)/CD)
u_cd = B//CD
n_cd = u_cd - l_cd + 1

n_u = B-A+1
print(n_u-(n_c + n_d - n_cd))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
import fractions
def lcm(x, y):
    return (x*y) // fractions.gcd(x, y)
# def gcd(x, y):
# 	while y:
# 		x, y = y, x % y
# 	return x
def main():
    A,B,C,D = map(int,input().split())
    E = lcm(C,D)
    Cc = B / C
    Dd = B / D
    Ee = B / E
    flo = A-1
    Cf = flo / C
    Df = flo / D
    Ef = flo / E
    All = B-(math.floor(Cc)+math.floor(Dd)-math.floor(Ee))
    Sub = flo-(math.floor(Cf)+math.floor(Df)-math.floor(Ef))
    print(All - Sub)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
listA=range(A)
listB=range(B+1)
listC=range(0,B+1,C)
listAC=range(0,A,C)
listD=range(0,B+1,D)
listAD=range(0,A,D)
listCD=range(0,B+1,C*D)
listACD=range(0,A,C*D)
lenA=len(listA)
lenB=len(listB)
lenC=len(listC)
lenAC=len(listAC)
lenD=len(listD)
lenAD=len(listAD)
lenCD=len(listCD)
lenACD=len(listACD)
ans=lenB-lenA-lenC+lenAC-lenD+lenAD+lenCD-lenACD
print(ans)

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 cnt(inp):
  min_ = inp * (int((A-1) // inp) + 1)
  max_ = inp * (int((B) // inp))
  num = (max_ - min_) / inp + 1
#  return([min_,max_,int(num)])
  return(int(num))

Ccnt = cnt(C)
Dcnt = cnt(D)
lcm = C*D // gcd(C,D)
CDcnt = cnt(lcm)

# print(Ccnt, Dcnt, CDcnt,(B+1-A)-Ccnt[2]-Dcnt[2]+CDcnt[2])
print((B+1-A)-Ccnt-Dcnt+CDcnt)

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(" "))
ans = 0
Bc = B // C
Bd = B // D
ck = gcd(C,D)
asb = C*D/ck
Bs = B//asb

newb = B - Bc - Bd + Bs

Ac = (A-1) // C
Ad = (A-1) // D
As = (A-1)//asb

newa = (A-1)-Ac-Ad+As

print(int(newb-newa))

Submission status: Wrong Answer

Solution code:
import math

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

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

A,B,C,D = map(int,input().split())
C_ = len(range(math.ceil(round(A/C,4))*C,B+1,C))
D_ = len(range(math.ceil(round(A/D,4))*D,B+1,D))
CD = lcm(C,D)
CD_ = len(range(math.ceil(round(A/CD,4))*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)

Submission status: Wrong Answer

Solution code:
import math

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

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

A,B,C,D = map(int,input().split())
C_ = len(range(math.ceil(round(A/C,2))*C,B+1,C))
D_ = len(range(math.ceil(round(A/D,2))*D,B+1,D))
CD = lcm(C,D)
CD_ = len(range(math.ceil(round(A/CD,2))*CD,B+1,CD))

print(B-A+1-C_-D_+CD_)

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)
x=b-a+1
y=g-f+1
z=k-h+1
w=m-l+1
if e>b:
    print(round(x-y-z))
else:
    print(round(x-y-z+w))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

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

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

x =int(b/c)-int(((a-1)/c))
y =int(b/d)-int(((a-1)/d))
n =lcm(c,d)
xy=int(b/n)-int(((a-1)/n))

ans = (b-a+1) - (x+y-xy)
print(ans)

Submission status: Wrong Answer

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

c = int(B / C)
d = int(B / D)
cd = 1

r = -1
a = -1
b = -1

if C > D:
    a = C
    b = D
else:
    a = D
    b = C

while True:
    r = a % b
    if r == 0:
        break
    a = b
    b = r
b = C*D/b
cd = int(B/b)

ans = (B-c-d+cd)

c = int((A-1) / C)
d = int((A-1) / D)
cd = int((A-1) / b)

print(ans - (A-1-c-d+cd))

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(int(to_b - to_a))

Submission status: Wrong Answer

Solution code:
A,B,C,D = [int(i) for i in input().split()]


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

Submission status: Wrong Answer

Solution code:
def L(l,a,b):
    for i in l:
        if i>=a:
            index1=l.index(i)
            break
    for i in reversed(l):
        if i <b:
            index2=len(l)-1
            break
        elif i==b:
            index2= l.index(i)+1
            print(index2)
            break
    del l[index2:]
    del l[:index1]
    return l

a, b, c ,d = [int(i)  for i in input().split()]
l1,l2=[],[]
i=0
sub=b-a+1
while i<b:
    i+=c
    l1.append(i)
i=0
while i<b:
    i+=d
    l2.append(i)

print(l1)
print(l2)

L1=L(l1, a,b)
L2=L(l2, a,b)

L2 = list(set(L2) - (set(L1) & set(L2)))
print(L1)
print(L2)

ans = sub-len(L1)-len(L2)
ans

Submission status: Wrong Answer

Solution code:
def saidaikouyaku(a, b):
    if b > a:
        a, b = b, a

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

A, B, C, D = map(int, input().split())
hani = B - A + 1
Cnum = int(B / C) - int((A - 1) / C)
Dnum = int(B / D) - int((A - 1) / D)
saisyoukoubai = int(C * D / saidaikouyaku(C, D))
koubainum = int(B / saisyoukoubai) - int((A - 1) / saisyoukoubai)
#print(hani)
#print(Cnum, Dnum, koubainum, saisyoukoubai)
print(hani - Cnum - Dnum + koubainum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

# n_CD = B // CD - (A-1) // CD #np.floor(B/CD) - np.floor((A-1)/CD)
n_CD = np.trunc(B/CD) - np.trunc((A-1)/CD)

Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
import fractions
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
    
ans = int(B - A + 1 -Cdiv - Ddiv + n_CD)#- n_C - n_D + 
print('{}'.format(ans))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
def lcm(x, y):
    return (x*y) // gcd(x, y)
def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
def main():
    A,B,C,D = map(int,input().split())
    E = lcm(C,D)
    Cc = B / C
    Dd = B / D
    Ee = B / E
    flo = A-1
    Cf = flo / C
    Df = flo / D
    Ef = flo / E
    All = B-(math.floor(Cc)+math.floor(Dd)-math.floor(Ee))
    Sub = flo-(math.floor(Cf)+math.floor(Df)-math.floor(Ef))
    print(All - Sub)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
bc=b//c
if a%c==0:
    ac=a//c-1
else:
    ac=a//c
bd=b//d
if a%d==0:
    ad=a//d-1
else:
    ad=a//d
e=c
f=d
while f:
    e, f = f, e % f
gcd=e
l=c*d/gcd
bl=b//l
if a%l==0:
    al=a//l-1
else:
    al=a//l
s=b-a+1
s2=int(bc-ac+bd-ad-bl+al)
print(s-s2)

Submission status: Wrong Answer

Solution code:
import math

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


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


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

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

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

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

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

# n_CD = B // CD - (A-1) // CD #np.floor(B/CD) - np.floor((A-1)/CD)
n_CD = np.int(np.trunc(B/CD) - np.trunc((A-1)/CD))

Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
import fractions
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
    
ans = int(B - A + 1 -Cdiv - Ddiv + n_CD)#- n_C - n_D + 
print('{}'.format(ans))

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 B%C==0 and not ((B-A+1)%C==0):
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%D==0 and not((B-A+1) % D == 0):
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if B%(lcm(C,D)) == 0 and not ((B-A+1)%lcm(C,D)==0):
    CD_div = (B-A+1)//lcm(C,D) + 1
else:
    CD_div = (B-A+1)//lcm(C,D)
print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

Solution code:
def koyaku(m, n):
    temp = 0
    while(m % n != 0):
        temp = n
        n = m % n
        m = temp
    return n

def koubai(m, n):
    return m * n / koyaku(m, n)

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

# 最小公倍数を求める。
if C > D:
    kou = koubai(C, D)
else:
    kou = koubai(D, C)

# AB間のCで割り切れる数を抽出
a = int(B / C) - int((A - 1) / C)

# AB間のDで割り切れる数を抽出
a2 = int(B / D) - int((A - 1) / D)

# 被り分の抽出
kaburi = int(B / kou) - int((A - 1) / kou)

print((B - A) - (a + a2 - kaburi) + 1)

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)


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

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

# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 1

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

End = B-endC-firstD + endCD
First = (A-1) - firstC - firstD + firstCD



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)
# print(End-First)

Submission status: Wrong Answer

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

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
num_c = b//c - (a-1)//c;
num_d = b//d - (a-1)//d; 
num_cd = b/lcm(c, d) - (a-1)//lcm(c,d);
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
if A%C==0:
    C1=int(A/C)
else:
    C1=int(A/C+1)
if B%C==0:
    C2=int(B/C+1)
else:
    C2=int(B/C)
if A%D==0:
    D1=int(A/D)
else:
    D1=int(A/D+1)
if B%D==0:
    D2=int(B/D+1)
else:
    D2=int(B/D)

for i in range(C1, C2+1):
    Count+=1
for j in range(D1, D2+1):
    if ((D*j)%C)!=0:
        Count+=1

print(B-A+1-Count)

Submission status: Wrong Answer

Solution code:
def koyaku(m, n):
    temp = 0
    while(m % n != 0):
        temp = n
        n = m % n
        m = temp
    return n

def koubai(m, n):
    return m * n / koyaku(m, n)

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

# 最小公倍数を求める。
if C > D:
    kou = koubai(C, D)
else:
    kou = koubai(D, C)

# AB間のCで割り切れる数を抽出
a = int(B / C) - int((A - 1) / C)

# AB間のDで割り切れる数を抽出
a2 = int(B / D) - int((A - 1) / D)

# 被り分の抽出
kaburi = int(B / kou) - int((A - 1) / kou)

print((B - A) - (a + a2 - kaburi))

Submission status: Wrong Answer

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

bcBaisu = b // c
bdBaisu = b // d
bcdLcm = b //( c * d / fractions.gcd(c, d))
acBaisu = (a -1) // c
adBaisu = (a-1) // d
acdLcm = (a-1) //( c * d / fractions.gcd(c, d))

karib = b - (bcBaisu + bdBaisu -bcdLcm)
karia = a - 1 - (acBaisu + adBaisu - acdLcm)

print(int(karib - karia))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = np.floor(B/CD) - np.floor((A-1)/CD)

Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
import fractions
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
    
ans = int(B - A + 1 -Cdiv - Ddiv + n_CD)#- n_C - n_D + 
print('{}'.format(ans))

Submission status: Wrong Answer

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

a = B-A+1
b =int(a/C)
c =int(a/D)
d =int(a/(C*D))
ans =a-(b+c-d)
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
lC = [_%C for _ in range(A,B+1)]
lD = [_%D for _ in range(A,B+1)]
ans = 0
l = [(lC[_] + lD[_]) for _ in range(len(lC)-1)]
dup = l.count(0)
ans = len(lC) - (lC.count(0) + lD.count(0) - dup)
print(ans)

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)


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

# if A%lcm(C,D) ==0 and firstCD > 0:
#     firstCD -= 1

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

End = B-endC-firstD + endCD
First = (A-1) - firstC - firstD + firstCD



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)
# print(End-First)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = np.floor(B/CD) - np.floor((A-1)/CD)

Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
import fractions
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
    
ans = B - A + 1 -Cdiv - Ddiv + n_CD#- n_C - n_D + 
print('{}'.format(ans))

Submission status: Wrong Answer

Solution code:
from math import ceil


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

c_count = ceil(b / c) - ceil(a / c)
d_count = ceil(b / d) - ceil(a / d)
cd_lcm = lcm(c, d)
cd_count = ceil(b // cd_lcm) - ceil(a / cd_lcm)

ans = 1 + b - a - (c_count + d_count - cd_count)
print(ans)

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 = list(map(int, input().split(' ')))
B_C = math.floor(B/C)
#print(B/C,math.floor(B/C))
B_D = math.floor(B/D)
#print(B/D,math.floor(B/D))
A_C = math.ceil(A/C) - 1
#print(A/C,math.ceil(A/C))
A_D = math.ceil(A/D) - 1
#print(A/D,math.ceil(A/D))

C_D = lcm(C,D)
B_C_D = math.floor(B/(C_D))
#print(B/(C_D),math.floor(B/(C_D)))
A_C_D = math.ceil(A/(C_D)) - 1
#print(A/(C_D),math.ceil(A/(C_D)))

print((B - A + 1) - (B_C + B_D - A_C - A_D - (B_C_D - A_C_D)))

Submission status: Wrong Answer

Solution code:
def koyaku(m, n):
    temp = 0
    while(m % n != 0):
        temp = n
        n = m % n
        m = temp
    return n

def koubai(m, n):
    return m * n / koyaku(m, n)

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

# 最小公倍数を求める。
if C > D:
    kou = koubai(C, D)
else:
    kou = koubai(D, C)

# AB間のCで割り切れる数を抽出
a = int(B / C) - int(A / C) - 1

# AB間のDで割り切れる数を抽出
a2 = int(B / D) - int(A / D) - 1

# 被り分の抽出
kaburi = int(B / kou) - int(A / kou)

print((B - A) - (a + a2 - kaburi))

Submission status: Wrong Answer

Solution code:
import math
import fractions


# C, Dの最小公倍数を求めておく
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


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

# A以上B以下にあるCとDの倍数を除外した残りの数字を求める
# Cの倍数を求める
start = math.floor((A - 1) / C)
end = math.floor(B / C)

c_multiples_count = end - start

# Dの倍数を求める
start = math.floor((A - 1) / D)
end = math.floor(B / D)

d_multiples_count = end - start

lcm_num = lcm(C, D)

# 公倍数を知る
start = math.floor((A - 1) / lcm_num)
end = math.floor(B / lcm_num)

# 公倍数が含まれる数を求める
lcm_multiples_count = end - start


# A以上B以下にあるCとDの倍数を除外した残りの数字を求める
# 公倍数については重複してカウントされているので足し戻す
ans = B - A - c_multiples_count - d_multiples_count + lcm_multiples_count + 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions
A, B, C, D = map(int, input().split())
CD = math.ceil(C * D / fractions.gcd(C, D))
AC = math.ceil(A / C)
BC = math.ceil(B / C)
C = BC - AC + 1
AD = math.ceil(A / D)
BD = math.ceil(B / D)
D = BD - AD + 1
ACD = math.ceil(A / CD)
BCD = math.ceil(B / CD)
CD = BCD - ACD + 1
print((B-A+1) - (C + D - CD))

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
#aまで
count_c_a = (a-1) // c
count_d_a = (a-1) // d
count_cd_a = (a-1) // (c*d)
#bまで
count_c_b = b // c
count_d_b = b // d
count_cd_b = b // (c*d)

print(b-(a-1) - ((count_c_b+count_d_b-count_c_a-count_d_a) - (count_cd_b-count_cd_a)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 22 21:34:54 2019

@author: owner
"""
import numpy as np

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

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

# %%
A, B, C, D = list(map(int, input().split()))
    
CD = lcm(C, D) 

n_C = np.int(np.floor(B/C) - np.floor((A-1)/C))
n_D = np.int(np.floor(B/D) - np.floor((A-1)/D))

n_CD = np.int(np.floor(B/CD) - np.floor((A-1)/CD))

Cdiv = B // C - (A-1) // C
Ddiv = B // D - (A-1) // D
import fractions
cddiv = (C*D)//fractions.gcd(C,D)
CDdiv = B // (cddiv) - (A-1) // (cddiv)
    
ans = B - A + 1 -Cdiv - Ddiv + n_CD#- n_C - n_D + 
print('{}'.format(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 = (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)
x=b-a+1
y=g-f+1
z=k-h+1
w=m-l+1
if e<b:
    print(x-y-z)
else:
    print(x-y-z+w)

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 B%C==0 and not ((B-A+1)%C==0):
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%D==0 and not((B-A+1) % D == 0):
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if B%(lcm(C,D)) == 0 and not ((B-A+1)%lcm(C,D)==0):
    CD_div = (B-A+1)//lcm(C,D) + 1
else:
    CD_div = (B-A+1)//lcm(C,D)
if C==1 or D==1:
    print(0)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
inputs = sys.stdin.readlines()
a, b, c, d = [int(x) for x in inputs[0].split(' ')]
e = c * d // gcd(c, d) # lcm(c, d)

def mod(a, b):
    r = a%b
    return r if r != 0 else b

def num(a, b, c):
    i = a + c - mod(a, c)
    if i > b:
        i = b+1
    return math.ceil((b+1 - i) / c)

c_ = num(a, b, c)
d_ = num(a, b, d)
e_ = num(a, b, e)

print(b+1 - a - c_ - d_ + e_)

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)

 # 1~B
nc1 = math.floor(B/C)
nd1 = math.floor(B/D)
nlcm1 = math.floor(B/lcm)

 # 1~A-1
nc2 = math.floor( (A-1)/C )
nd2 = math.floor( (A-1)/D )
nlcm2 = math.floor( (A-1)/lcm )

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

n1 = B - nc1 - nd1 + nlcm1
n2 = A - 1 - nc2 - nd2 +nlcm2

n = n1 - n2

print(n)

 # 何故か不正解、納得いかん

Submission status: Wrong Answer

Solution code:
import math


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


a, b, c, d = map(int, input().split())  # 複数数値入力

# cとdの最小公倍数
lcm = c * d / gcd(c, d)

# print(lcm)
# print(b - a + 1)
# print(int(b / c) - int((a - 1) / c))
# print(int(b / d) - int((a - 1) / d))
# print(int(b/lcm)-int((a-1)/lcm))
# print(b - a + 1 - math.floor(b / c) - math.floor(b/d) +
# math.floor((a-1) / c) + math.floor((a-1)/d) + (math.floor(b/lcm) - math.floor((a-1)/lcm)))
print(int(b - a + 1 - b // c - b//d +
          (a-1) // c + (a-1)//d + ((b//lcm) - (a-1)//lcm)))

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

AtoB =  B - (A-1)

div_C = int(B/C) - int((A-1)/C)
div_D = int(B/D) - int((A-1)/D)
div_CD = int(B/lcm(C,D)) - int((A-1)/lcm(C,D))

print(AtoB - div_C - div_D + div_CD)

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(" "))
ans = 0
Bc = B // C
Bd = B // D
ck = 0
if C <= D:
        ck = gcd(C, D)
else:
        ck = gcd(D,C)
asb = C*D/ck
Bs = B//asb

newb = B - Bc - Bd + Bs

Ac = (A-1) // C
Ad = (A-1) // D
As = (A-1)//asb

newa = (A-1)-Ac-Ad+As

print(int(newb-newa))

Submission status: Wrong Answer

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

bcBaisu = b // c
bdBaisu = b // d
bcdLcm = b //( c * d / fractions.gcd(c, d))
acBaisu = (a -1) // c
adBaisu = (a-1) // d
acdLcm = (a-1) //( c * d / fractions.gcd(c, d))

karib = b - (bcBaisu + bdBaisu -bcdLcm)
karia = a - 1 - (acBaisu + adBaisu - acdLcm)

print(karib - karia)