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:
# Euclidean Algorithm
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

# lcm (least common multiple)
def lcm(m, n):
    return m//gcd(m, n)*n

a, b, c, d = map(int, input().split())
ndiv = (b-a)//c + (b-a)//d - (b-a)//lcm(c,d)
print(b - a - ndiv )

Submission status: Wrong Answer

Solution code:
import fractions
A, B, C, D = map(int, input().split())
cnt = 0
ac = (A-1) // C
bc = B // C
ad = (A-1) // D
bd = B // D
gcd_b = B // (C*D//fractions.gcd(C, D))
gcd_a = (A-1) // (C*D//fractions.gcd(C, D))
total = B - A + 1
a = bc - ac
b = bd - ad
gcdx = gcd_b - gcd_a
print(ac, bc, ad, bd, gcd_b, gcd_a)

print(total-a-b+gcdx)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#数I
A,B,C,D = map(int,input().split())
S = B-A+1
print(S-(S//C + S//D - S//(C*D)))

Submission status: Wrong Answer

Solution code:
import math,fractions
A,B,C,D=map(float,input().split())
E=C*D//fractions.gcd(C,D)

ac=A//C
ad=A//D
bc=B//C
bd=B//D
ae=A//E
be=B//E

s=bc-ac
t=bd-ad
u=be-ae

print(s,t,u)
print(int(B-A+1 -(s+t) +u))

Submission status: Wrong Answer

Solution code:
import math,fractions
A,B,C,D=map(int,input().split())
E=C*D//fractions.gcd(C,D)

ac=A//C
ad=A//D
bc=B//C
bd=B//D
ae=A//E
be=B//E

s=bc-ac
t=bd-ad
u=be-ae

print(B-A+1 -(s+t) +u)

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heappush, heappop
from fractions import gcd
#input = sys.stdin.readline

def main():
    a,b,c,d=map(int,input().split())
    dc=d*c/gcd(d,c)
    print(b-a+1-(b//c-(a-1)//c)-(b//d-(a-1)//d)+(b//(dc)-(a-1)//(dc)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions

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

c_d = (c * d) / fractions.gcd(c, d)

a -= 1

tmp_b = b - (b//c + b//d - b//c_d)
tmp_a = a - (a//c + a//d - a//c_d)

print(tmp_b-tmp_a)

Submission status: Wrong Answer

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

c_d = c * d / fractions.gcd(c, d)

def check(bb, cc):
    if bb < cc:
        return 0
    if b%cc == 0:
        tmp_b = bb
    else:
        tmp_b = cc*(bb//cc)

    return tmp_b//cc

under_b_c = check(b,c)
under_b_d = check(b,d)
under_b_cd = check(b,c_d)
tmp_b = b-under_b_c-under_b_d+under_b_cd
#print(tmp_b)

under_a_c = check(a-1,c)
under_a_d = check(a-1,d)
under_a_cd = check(a-1,c_d)
tmp_a = (a-1)-under_a_c-under_a_d+under_a_cd
#print(under_a_c, under_a_d, under_a_cd)
#print(tmp_a)

print(int(tmp_b-tmp_a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

zen=a-1
ack=int(zen//c)
adk=int(zen//d)
acdk=int(zen//(c*d))

aans=zen-ack-adk+acdk

ck=int(b//c)
dk=int(b//d)
cdk=int(b//(c*d))

ans=b-ck-dk+cdk

ans=ans-aans

print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
count=0
for i in range(a,b):
  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())

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

cd = lcm(c, d)

b_c = b//c
b_d = b//d
b_cd = b//cd
bb = b - (b_c + b_d - b_cd)

a_c = a//c
a_d = a//d
a_cd = a//cd
aa = a - (a_c + a_d - a_cd)

print(bb-aa)

Submission status: Wrong Answer

Solution code:
#131c
import math
import fractions

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

#####################################
#最小公倍数の算出
def lcm(x, y):
    #return (x * y) // math.gcd(x, y)
    return (x * y) // fractions.gcd(x , y)
#####################################

#A 以上 B 以下の整数のうち、C でも D でも割り切れないものの個数を求めてください。
#1≤A≤B≤10**18
all_number = B - A + 1
C_number = int(B/C) - math.ceil(A/C) + 1
D_number = int(B/D) - math.ceil(A/D) + 1
CD = lcm(C, D)
CD_number = int(B/(CD)) - math.ceil(A/(CD)) + 1

#print(all_number,C_number,D_number,CD_number)
print(all_number - C_number - D_number + CD_number)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

A, B, C, D = map(int, input().split())
total = B - A + 1
CD = lcm(C, D)

C_count = math.floor(B / C) - math.floor((A-1) / C)
D_count = math.floor(B / D) - math.floor((A-1) / D)
CD_count = math.floor(B / CD) - math.floor((A-1) / CD)

result = total - C_count - D_count + CD_count

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

    # def resolve():
A, B, C, D = map(int, input().split())
total = B - A + 1
CD = lcm(C, D)

C_count = math.floor(B / C) - math.floor(A / C)
if (A % C) == 0:
    C_count += 1
D_count = math.floor(B / D) - math.floor(A / D)
if (A % D) == 0:
    D_count += 1
CD_count = math.floor(B / CD) - math.floor(A / CD)
if (A % CD) == 0:
    CD_count += 1

result = total - C_count - D_count + CD_count

print(result)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

def solve():
    A,B,C,D = map(int, input().split())
    c = B//C - A//C
    if A % C == 0:
        c += 1
    d = B//D - A//D
    if B % C == 0:
        d += 1
    r = lcm(C,D)
    e = B//r - A//r
    ans = (B-A+1) - (c+d-e)
    if ans < 0:
        return 0
    return ans

print(solve())

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

def solve():
    A,B,C,D = map(int, input().split())
    c = B//C - A//C
    if A % C == 0:
        c += 1
    d = B//D - A//D
    if B % C == 0:
        d += 1
    r = lcm(C,D)
    e = B//r - A//r

    return (B-A+1) - (c+d-e)

print(solve())

Submission status: Wrong Answer

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

def calc_kukan_num(mod):
    start = A if A % mod == 0 else A + mod - (A+mod) % mod
    return (B - start) // mod + 1
print(B-A+1-calc_kukan_num(C)-calc_kukan_num(D)+calc_kukan_num(C*D))

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)
ans=b//d + b//c - (a-1)//c - (a-1)//d - b//lcm(c,d) - (a-1)//lcm(c,d)
ans=b-a+1-ans
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

cd_gcd = gcd(c, d)
cd_lcm = c * d // cd_gcd

ans = (b - a + 1) - (b - a +1)//c - (b - a +1)//d + (b - a +1)//cd_lcm
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

cd_gcd = gcd(c, d)
cd_lcm = c * d // cd_gcd

ans = (b - a + 1) - (b - a -1)//c - (b - a -1)//d + (b - a -1)//cd_lcm
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

cd_gcd = gcd(c, d)
cd_lcm = c * d // cd_gcd

ans = (b - a) - (b - a)//c - (b - a)//d + (b - a)//cd_lcm
print(ans)

Submission status: Wrong Answer

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


x = ((b+1) // c) - ((a+1) // c)
y = ((b+1) // d) - ((a+1) // d)


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


z = ((b+1) // e) - ((a+1) // e)


print((b-a) - (x+y-z) + 1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

a, b, c, d = map(int, input().split())
lcm = c * d / gcd(c, d)

def solve(n, lcm):
  res = n - n // c - n // d + n // lcm
  return res

print(int(solve(b, lcm) - solve(a-1, lcm)))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

def solve(n):
  lcm = c * d / gcd(c, d)
  res = n - n // c - n // d + n // lcm
  return res

print(int(solve(b) - solve(a-1)))

Submission status: Wrong Answer

Solution code:
def cnt(A, B, X):
    A1 = -(-A // X)
    B1 = B // X
    return B1 - A1 + 1

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

Submission status: Wrong Answer

Solution code:
def cnt(A, B, X):
    A1 = -(-A // X)
    B1 = B // X
    return B1 - A1 + 1

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

Submission status: Wrong Answer

Solution code:
import sys
import os
import fractions

MOD = 10 ** 9 + 7


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = list(map(int, sys.stdin.readline().split()))
    E = B - A + 1

    ret = 0
    ret += B // C
    ret += B // D
    ret -= (A - 1) // C
    ret -= (A - 1) // D
    ret -= B // lcm(C, D)
    ret += A // lcm(C, D)
    print(E - ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import fractions

MOD = 10 ** 9 + 7


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = list(map(int, sys.stdin.readline().split()))
    E = B - A + 1

    ret = 0
    ret += B // C
    ret += B // D
    ret -= (A - 1) // C
    ret -= (A - 1) // D
    ret -= B // lcm(C, D)
    print(E - ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import fractions

MOD = 10 ** 9 + 7


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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A, B, C, D = list(map(int, sys.stdin.readline().split()))
    E = B - A + 1

    ret = 0
    ret += B // C
    ret += B // D
    ret -= (A - 1) // C
    ret -= (A - 1) // D
    ret -= B // lcm(C, D)
    ret -= (A - 1) // lcm(C, D)
    print(E - ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = map(int,input().split())
A -= 1
g = fractions.gcd(C, D)
l = C * D / g

sA = A // C
eA = A // D
lA = A - eA - sA + A // l

sB = B // C
eB = B // D
lB = B - eB - sB + B // l
print(int(lB - lA))

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = map(int,input().split())
A -= 1
g = fractions.gcd(C, D)
l = C * D / g

sA = A // C
eA = A // D
lA = A - (eA + sA - A // l)

sB = B // C
eB = B // D
lB = B - (eB + sB - B // l)
print(int(lB - lA))

Submission status: Wrong Answer

Solution code:
import fractions

A,B,C,D = map(int,input().split())
A -= 1
g = fractions.gcd(C, D)
l = C * D / g

sA = A // C
eA = A // D
lA = A - (eA + sA) + A // l

sB = B // C
eB = B // D
lB = B - (eB + sB) + B // l
print(int(lB - lA))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

def count(n):
  c = (B-A)//n
  if A%n > B%n or A%n == 0:
    c += 1
  return c

c = B-A+1-count(C)-count(D)+count(lcm)
print(int(c))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

def count(n):
  c = (B-A)//n
  if A%n > B%n or A%n == 0:
    c += 1
  return c

c = B-A+1-count(C)-count(D)+count(lcm)
print(c)

Submission status: Wrong Answer

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

rc=(B//C)-((A-1)//C)#割り切れる数
rd=(B//D)-((A-1)//D)#割り切れる数

rcd=(B//(C*D/gcd(C,D)))-((A-1)//(C*D/gcd(C,D)))
print(int((B-A+1)-(rc+rd-rcd)))

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
k=0
rc=(B//C)-((A-1)//C)#割り切れる数
rd=(B//D)-((A-1)//D)#割り切れる数
rcd=(B//(C*D))-((A-1)//(C*D))
print((B-A+1)-(rc+rd-rcd))

Submission status: Wrong Answer

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

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

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

print(k(b)-k(a))

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
ans = 0
"""
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
k = b-a+1

amri_c = a % c
k_c = (k-(amri_c+1))//c + 1

amri_d = a % d
k_d = (k-(amri_d+1))//d + 1

amri_cd = a % (c*d)
k_cd = (k-(amri_cd+1))//(c*d) + 1

#print(k_c, k_d, k_cd)
ans = k-k_c-k_d+k_cd

print(ans)

Submission status: Wrong Answer

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

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

k = b-a+1

amri_c = a % c
k_c = (k-(amri_c+1))//c + 1

amri_d = a % d
k_d = (k-(amri_d+1))//d + 1

amri_cd = a % lcm(c, d)
k_cd = (k-(amri_cd+1))//lcm(c, d) + 1

#print(k_c, k_d, k_cd)
ans = k-k_c-k_d+k_cd

print(ans)

Submission status: Wrong Answer

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

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

k = b-a+1

amri_c = a % c
if amri_c == 0:
    amri_c = c
    k_c = (k - (amri_c - 1)) // c
else:
    k_c = (k - (amri_c - 1)) // c + 1

amri_d = a % d
if amri_d == 0:
    amri_d = d
    k_d = (k - (amri_d - 1)) // d
else:
    k_d = (k - (amri_d - 1)) // d + 1

amri_cd = a % lcm(c, d)
if amri_cd == 0:
    amri_cd = lcm(c, d)
    k_cd = (k - (amri_cd - 1)) // lcm(c, d)
else:
    k_cd = (k - (amri_cd - 1)) // lcm(c, d) + 1

ans = k-k_c-k_d+k_cd

print(ans)

Submission status: Wrong Answer

Solution code:
#abc133 c
from fractions import gcd
a,b,c,d=map(int,input().split())
"""
def gcd(x,y):
    if y==1:
        return x
    return gcd(y,x%y)
"""

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

e=lcm(c,d) #c,dの最小公倍数

def kosu(num):
    z=num
    nc=int(num/c)
    nd=int(num/d)
    ne=int(num/e)
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

print(ans)

Submission status: Wrong Answer

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

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

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

e=lcm(c,d) #c,dの最小公倍数

def kosu(num):
    z=num
    nc=int(num/c)
    nd=int(num/d)
    ne=int(num/e)
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

print(ans)

Submission status: Wrong Answer

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

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

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

e=lcm(c,d) #c,dの最小公倍数


def kosu(num):
    z=num
    nc=int(num/c)
    nd=int(num/d)
    ne=int(num/e)
    return z-nc-nd+ne

ans=kosu(b)-kosu(a-1)

print(ans)

Submission status: Wrong Answer

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

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

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

e=lcm(c,d) #c,dの最小公倍数


n=b-a+1
nc=int(b/c)-int((a-1)/c)
nd=int(b/d)-int((a-1)/d)
ne=int(b/e)-int((a-1)/e)

nf=nc+nd-ne#cまたはdの個数

ans=n-nf
print(ans)

Submission status: Wrong Answer

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

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

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

e=lcm(c,d) #c,dの最小公倍数


n=b-a+1
nc=int(b/c)
nd=int(b/d)
ne=int(b/e)
if a!=1:
    nc-=int((a-1)/c)
    nd-=int((a-1)/d)
    ne-=int((a-1)/e)


nf=nc+nd-ne#cまたはdの個数

ans=n-nf
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

ABmulC = B//C - (A-1)//C
ABmulD = B//D - (A-1)//D
LCM = lcm(C,D)
ABmulLCM = B//LCM - A//LCM

ans = B - A + 1
ans -= ABmulC + ABmulD
ans += ABmulLCM
print(ans)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
v,h = max(c,d),min(c,d)
while (v%h != 0):
    t = v
    u = h
    v = h
    h = t%u
lcm = max(c,d)*(int(min(c,d)/h))
r = 0
f = h
a -= 1
e = b-a
r += int(b/c)
r += int(b/d)
r -= int(b/lcm)
r -= int(a/c)
r -= int(a/d)
r += int(a/lcm)
print(e-r)

Submission status: Wrong Answer

Solution code:
a,b,c,d = map(int,input().split())
v,h = max(c,d),min(c,d)
while (v%h != 0):
    t = v
    u = h
    v = h
    h = t%u
lcm = max(c,d)*(int(min(c,d)/h))
r = 0
f = h
e = (b+1)-a
a -= 1
r += int(b/c)
r += int(b/d)
r -= int(b/lcm)
r -= int(a/c)
r -= int(a/d)
r += int(a/lcm)
print(e-r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

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

# (B - A + 1) - n(C) - n(D) + n(C∩D)

def count_divisible_numbers(x):
  a = (A-1) // 2
  b = B // 2
  return b - a

n_C = count_divisible_numbers(C)
n_D = count_divisible_numbers(D)
CD_lcm = C*D // fractions.gcd(C, D)
n_CD = count_divisible_numbers(CD_lcm)

res = (B - A + 1) - n_C - n_D + n_CD
print(res)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

# (B - A + 1) - n(C) - n(D) + n(C∩D)

def count_divisible_numbers(A, B, x):
  a = math.ceil(A/x)
  b = math.floor(B/x)
  return b - a + 1

n_C = count_divisible_numbers(A, B, C)
n_D = count_divisible_numbers(A, B, D)
CD_lcm = C*D // fractions.gcd(C, D)
n_CD = count_divisible_numbers(A, B, CD_lcm)

res = (B - A + 1) - n_C - n_D + n_CD
print(res)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

# (B - A + 1) - n(C) - n(D) + n(C∩D)

def count_divisible_numbers(x):
  a = math.ceil(A/x)
  b = math.floor(B/x)
  if a <= b:
    return b - a + 1
  else:
    return 0

n_C = count_divisible_numbers(C)
n_D = count_divisible_numbers(D)
CD_lcm = C*D // fractions.gcd(C, D)
n_CD = count_divisible_numbers(CD_lcm)

res = (B - A + 1) - n_C - n_D + n_CD
print(res)

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)

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

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

def f(n, m, l):
  a = n // l
  if a * l < n:
    a += 1
  b = m // l
  return b - a + 1

def main():
    a, b, c, d = na()
    x = b - a + 1
    print(x - f(a, b, c) - f(a, b, d) + f(a, b, lcm(c, d)))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

# TLE
def test():
    count = 0 
    for x in range(a, b+1):
        if x%c != 0 and x%d != 0:
            count+=1
    print(count)
# ズレを考慮できてない
def test2():
    diff = b-a+1
    print(diff -int(diff/c) -int(diff/d) +int(diff/lcm(c,d)))

def main():
    zero2b = (b -int(b/c) -int(b/d) +int(b/lcm(c,d)))
    zero2a_1 = ((a-1) -int((a-1)/c) -int((a-1)/d) +int((a-1)/lcm(c,d)))
    print(zero2b - zero2a_1)

main()

Submission status: Wrong Answer

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

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

def main():
    left = (b -int(b/c) -int(b/d) +int(b/lcm(c,d)))
    right = ((a-1) -int((a-1)/c) -int((a-1)/d) +int((a-1)/lcm(c,d)))
    print(left - right)
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def count(b, c, d):
    return b - b//c - b//d + b//(c * d * gcd(c, d))

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd

"""

+ その範囲の6の倍数の数
+ その範囲の8の倍数の数
- その範囲の48の倍数の数
で答えが求まる

"""

def v_count(n, start, end):
  start_pop = start % n
  start = start + (n - start_pop)
  return int((end - start) / n) + 1

A, B, C, D = list(map(lambda x: int(x), input().split()))

all_count = B - A + 1

c_count = v_count(C, A, B)
d_count = v_count(D, A, B)
min_cd = (C * D) // gcd(C, D)
cd_count = v_count(min_cd, A, B)

print(all_count - c_count - d_count + cd_count)

Submission status: Wrong Answer

Solution code:

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

def calc_lcd(x, y):
    if x < y:
        temp = x
        x = y
        y = temp
    
    r = x % y
    z = x * y
    while r != 0:
        x = y
        y = r
        r = x % y
    
    return z // y

lcd = calc_lcd(c, d)
a -= 1
#print(b // d)
#print("b:{0} b / c:{1} b / d:{2} b / lcd:{3} a:{4} a / c:{5} a / d:{6} a / lcd:{7}".format(b, b // c, b // d, b // lcd, a, a // c, a // d, a // lcd))
print(b - b // c - b // d + b // lcd - a - a // c - a // d + a // lcd)

Submission status: Wrong Answer

Solution code:

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

def calc_lcd(x, y):
    if x < y:
        temp = x
        x = y
        y = temp
    
    r = x % y
    z = x * y
    while r != 0:
        x = y
        y = r
        r = x % y
    
    return z // y

lcd = calc_lcd(c, d)
a -= 1
print(b // d)
#print("b:{0} b / c:{1} b / d:{2} b / lcd:{3} a:{4} a / c:{5} a / d:{6} a / lcd:{7}".format(b, b // c, b // d, b // lcd, a, a // c, a // d, a // lcd))
print(b - b // c - b // d + b // lcd - a - a // c - a // d + a // lcd)

Submission status: Wrong Answer

Solution code:

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

def calc_lcd(a, b):
    if a < b:
        temp = a
        a = b
        b = temp
    
    r = a % b
    x = a * b
    while r != 0:
        a = b
        b = r
        r = a % b
    
    return x / b

lcd = calc_lcd(c, d)
a -= 1
#print("b:{0} b / c:{1} b / d:{2} b / lcd:{3} a:{4} a / c:{5} a / d:{6} a / lcd:{7}".format(b, int(b / c), int(b / d), int(b / lcd), a, int(a / c), int(a / d), int(a / lcd)))
print(int(b - int(b / c) - int(b / d) + int(b / lcd) - (a - int(a / c) - int(a / d) + int(a / lcd))))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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


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


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

    all = B - A + 1
    c = -(-all // C)
    d = -(-all // D)
    cd = -(-all // lcm(C, D))

    print(all - c - d + cd)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

    all = B - A + 1
    c = -(-(B - A) // C)
    d = -(-(B - A) // D)
    cd = -(-(B - A) // (C * D))

    print(all - c - d + cd)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A,B,C,D = map(int,input().split())
x = gcd(C,D)
count = 0
x = int(C*D/x)
a = (B/C)-((A-1)/C)
b = (B/D)-((A-1)/D)
c = (B/x)-((A-1)/x)
a = math.ceil(a)
b = math.ceil(b)
c = math.ceil(c)
ans = B-A+1 - (a+b-c)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
count = 0
a = (B/C)-(A/C)
b = (B/D)-(A/D)
c = (B/(C*D))-(A/(C*D))

if a > 1:
  a = math.ceil(a)
else:
  a = 0
if b > 1:
  b = math.ceil(b)
else:
  b = 0
if c > 1:
  c = math.ceil(c)
else:
  c = 0
if A%C == 0 and B%C == 0:
  a += 1
if A%D == 0 and B%D == 0:
  b += 1
if A%(C*D) ==0 and B%(C*D) == 0:
  c += 1

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

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
count = 0
x = math.ceil((B/C)-(A/C))
y = math.ceil((B/D)-(A/D))
z = math.ceil((B/(C*D))-(A/(C*D)))

if A%C == 0 and B%C == 0:
  x += 1
if A%D == 0 and B%D == 0:
  y += 1
if A%(C*D) ==0 and B%(C*D) == 0:
  z += 1

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

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
count = 0
x = math.ceil((B/C)-(A/C))
y = math.ceil((B/D)-(A/D))
z = math.ceil((B/(C*D))-(A/(C*D)))

if A%C == 0:
  x += 1
if A%D == 0:
  y += 1
if A%(C*D) ==0:
  z += 1

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

Submission status: Wrong Answer

Solution code:
import math
A,B,C,D = map(int,input().split())
count = 0
x = math.ceil((B/C)-(A/C))
y = math.ceil((B/D)-(A/D))
z = math.ceil((B/(C*D))-(A/(C*D)))

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

Submission status: Wrong Answer

Solution code:
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())

#nc=B//C-(A-1)//C
nc=int(B/C)-int((A-1)/C)
#nd=B//D-(A-1)//D
nd=int(B/D)-int((A-1)/D)
cd=int(C*D/gcd(C,D))
#ncd=B//cd-(A-1)//cd
ncd=int(B/cd)-int((A-1)/cd)
print(int(B-A+1-nc-nd+ncd))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())

#nc=B//C-(A-1)//C
nc=int(B/C)-int((A-1)/C)
#nd=B//D-(A-1)//D
nd=int(B/D)-int((A-1)/D)
cd=int(C*D/gcd(C,D))
#ncd=B//cd-(A-1)//cd
ncd=int(B/cd)-int((A-1)/cd)
print(B-A+1-nc-nd+ncd)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())
if A%C==0:
    nc=int(B/C)-int(A/C)+1
else:
    nc=int(B/C)-int(A/C)
if A%D==0:
    #nd=int(B/C)-int(A/C)+1
    nd=int(B/D)-int(A/D)+1
else:
    nd=int(B/D)-int(A/D)
cd=int(C*D/gcd(C,D))
if A%cd==0:
    ncd=int(B/cd)-int(A/cd)+1
else:
    ncd=int(B/cd)-int(A/cd)
print(int(B-A+1-nc-nd+ncd))

Submission status: Wrong Answer

Solution code:
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())
if A%C==0:
    nc=int(B/C)-int(A/C)+1
else:
    nc=int(B/C)-int(A/C)
if A%D==0:
    #nd=int(B/C)-int(A/C)+1
    nd=int(B/D)-int(A/D)+1
else:
    nd=int(B/D)-int(A/D)
cd=int(C*D/gcd(C,D))
if A%cd==0:
    ncd=int(B/cd)-int(A/cd)+1
else:
    ncd=int(B/cd)-int(A/cd)
print(B-A+1-nc-nd+ncd)

Submission status: Wrong Answer

Solution code:
def gcd(a,b):#最大公約数を返す。Euclid
    if a<b:
        a,b=b,a
    c=a%b
    if c==0:
        return b
    return gcd(b,c)
A,B,C,D=map(int,input().split())
if A%C==0:
    #nc=int(B/C)-int(A/C)+1
    nc=B//C-A//C+1
else:
    #nc=int(B/C)-int(A/C)
    nc=B//C-A//C
if A%D==0:
    #nd=int(B/C)-int(A/C)+1
    #nd=int(B/D)-int(A/D)+1
    nd=B//D-A//D+1
else:
    #nd=int(B/D)-int(A/D)
    nd=B//D-A//D
cd=C*D/gcd(C,D)
if A%cd==0:
    #ncd=int(B/cd)-int(A/cd)+1
    ncd=B//cd-A//cd+1
else:
    #ncd=int(B/cd)-int(A/cd)
    ncd=B//cd-A//cd
#print("nc,nd,ncd",nc,nd,ncd)
print(B-A+1-nc-nd+ncd)