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

gcd = 1
for i in range(2,min(C,D)):
	if C%i == 0 and D%i == 0:
		gcd = max(i,gcd)

Bnondiv = B - (B//C + B//D - (B*gcd)//(C*D))
Anondiv = (A-1) - ((A-1)//C + (A-1)//D - (A-1)*(gcd)//(C*D))
print(int(Bnondiv-Anondiv))

Submission status: Wrong Answer

Solution code:
a, b, c, d= map(int, input().split())
def gcd(c,d):
    if c%d == 0:
        return d
    else:
        return gcd(d,c%d)
def num(n,c,d):
    lcm = (c  /gcd(c, d)) * d
    return n- int(n/c) - int(n/d) + int(n/lcm)

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

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
def gcd(c,d):
    if c%d == 0:
        return d
    else:
        return gcd(d,c%d)
def num(n,c,d):
    lcm = c * d /gcd(c, d)
    return n- int(n/c) - int(n/d) + int(n/lcm)

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

Submission status: Wrong Answer

Solution code:
import fractions

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


num_b = b - (b // c) - (b // d) + (b // (c * d / fractions.gcd(c, d)))
num_a = a - 1 - ((a - 1 ) // c) - ((a - 1) // d) + ((a - 1) // (c * d / fractions.gcd(c, d)))
num = num_b - num_a

print(int(num))

Submission status: Wrong Answer

Solution code:
import fractions

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

num_b = b - (b // c) - (b // d) + (b // (c * d / fractions.gcd(c, d)))
num_a = a - 1 - ((a - 1 ) // c) - ((a - 1) // d) + ((a - 1) // (c * d / fractions.gcd(c, d)))
num = num_b - num_a

print(num)

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int((A-1)/n)
    n_count = n_upper - n_lower
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C * D) / gcd(C, D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n)
    n_count = n_upper - n_lower
    if A%n == 0:
        n_count = n_count + 1
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C * D) / gcd(C, D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n)
    n_count = n_upper - n_lower
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C * D) / gcd(C, D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n)
    n_count = n_upper - n_lower
    print(n_count)
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C * D) / gcd(C, D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n - 1)
    n_count = n_upper - n_lower 
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C * D) / gcd(C, D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n + 1)
    n_count = n_upper - n_lower + 1
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C * D) / gcd(C, D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n + 1)
    n_count = n_upper - n_lower + 1
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = (C / gcd(C, D)) * D
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def count(n, A, B):
    n_upper = int(B/n)
    n_lower = int(A/n + 1)
    n_count = n_upper - n_lower + 1
    return n_count

def main():
    A, B, C ,D  = list(map(int, input().split(" ")))
    C_count = count(C, A, B)
    D_count = count(D, A, B)
    s = int((C / gcd(C, D)) * D)
    CD_count = count(s, A ,B)
    fcount = (B - A + 1) - (C_count + D_count - CD_count)
    print(fcount)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions

def main09():
    data = input().split()
    num = []
    for i in range(4):
        num.append(int(data[i]))
    lcm = int(num[2] * num[3] / fractions.gcd(num[2],num[3]))
    kosu = num[1] - num[0] + 1
    result = 0
    if kosu > lcm:
        block = int(kosu / lcm)
        result = result + block * karif(num[0],num[0]+lcm,num[2],num[3])
        amari = int(kosu % lcm)
        result = result + karif(num[0],num[0]+amari,num[2],num[3])
    else:
        result = karif(num[0],num[0]+kosu,num[2],num[3])
    print(result)
            
def karif(hazime,owari,d1,d2):
    result = 0
    for i in range(hazime,owari,1):
        hantei = True
        if i % d1 == 0:
            hantei = False
        if i % d2 == 0:
            hantei = False
        if hantei:
            result = result + 1
    return result

if __name__ == "__main__":
    main09()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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


def num_div(n):
    return int(n // c + n // d - n // l)


print((b - a + 1) - (num_div(b) - num_div(a - 1)))

Submission status: Wrong Answer

Solution code:
#gcd関数(最大公約数を求める)
from fractions import gcd
import math
a,b,c,d = map(int,input().split())

#c,dにおける最小公倍数を求める
z = c*d // gcd(c,d)
#aからbまでの全体の個数
i = b - a + 1
#(l,r)の範囲でgの倍数の個数
#k= (r+g)-(l+g-1)/g
#最小公倍数で割れる個数
y = ((b + z) - (a + z - 1)) / z
#四捨五入して切り上げれるものは切り上げている
y = math.ceil(y)
#cで割り切れる個数
x = ((b + c) - (a + c - 1)) / c
x = math.ceil(x)
#dで割り切れる個数
w = ((b + d) - (a + d - 1)) / d
w = math.ceil(w)
#全体からcの倍数とdの倍数を引いて、最小公倍数を足す
print(i - x - w + y)

Submission status: Wrong Answer

Solution code:
import fractions

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

U = B - A + 1

def number(R):
        return ((B // R) - ((A - 1) // R))

possible_C = number(C)
possible_D = number(D)
possible_CD = number((C * D) // fractions.gcd(C, D))

print(U)
print(possible_C)
print(possible_D)
print(possible_CD)

print(U - (possible_C + possible_D) + possible_CD)

Submission status: Wrong Answer

Solution code:
#gcd関数(最大公約数を求める)
from fractions import gcd
import math
a,b,c,d = map(int,input().split())

#c,dにおける最小公倍数を求める
z = c*d // gcd(c,d)

i = b - a + 1

y = ((b + z) - (a + z - 1)) / z
y = math.ceil(y)
x = ((b + c) - (a + c - 1)) / c
x = math.ceil(x)
w = ((b + d) - (a + d - 1)) / d
w = math.ceil(w)

print(i - x - w + y)

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)


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

def main():
    A, B, C_, D_ = (int(x) for x in input().split())

    if C_ > D_:
        C, D = D_, C_
    else:
        C, D = C_, D_
        

    lcm_CD = C * D / gcd(C, D)
    
    div_C = int(B // C) - int((A - 1) // C)
    div_D = int(B // D) - int((A - 1) // D)
    div_lcm_CD = int(B // lcm_CD) - int((A - 1) // lcm_CD)
    
    answer = B - A + 1 - div_C - div_D + div_lcm_CD

    if A == 0:
        print(answer - 1)
    else:
        print(answer)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)


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

def main():
    A, B, C_, D_ = (int(x) for x in input().split())

    if C_ > D_:
        C, D = D_, C_
    else:
        C, D = C_, D_
        

    lcm_CD = C * D / gcd(C, D)
    
    div_C = int(B / C) - int((A - 1) / C)
    div_D = int(B / D) - int((A - 1) / D)
    div_lcm_CD = int(B / lcm_CD) - int((A - 1) / lcm_CD)
    
    answer = B - A + 1 - div_C - div_D + div_lcm_CD

    if A == 0:
        print(answer - 1)
    else:
        print(answer)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)


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

def main():
    A, B, C, D = (int(x) for x in input().split())
    lcm_CD = C * D / gcd(C, D)
    
    div_C = int(B / C) - int((A - 1) / C)
    div_D = int(B / D) - int((A - 1) / D)
    div_lcm_CD = int(B / lcm_CD) - int((A - 1) / lcm_CD)
    
    answer = B - A + 1 - div_C - div_D + div_lcm_CD

    if A == 0:
        print(answer - 1)
    else:
        print(answer)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)


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

def main():
    A, B, C, D = (int(x) for x in input().split())
    lcm_CD = C * D / gcd(C, D)
    
    div_C = int(B / C) - int((A - 1) / C)
    div_D = int(B / D) - int((A - 1) / D)
    div_lcm_CD = int(B / lcm_CD) - int((A - 1) / lcm_CD)
    
    answer = B - A + 1 - div_C - div_D + div_lcm_CD
    
    print(answer)

if __name__ == "__main__":
    main()

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())
CD=lcm(C,D)
maxC=int(B/C)*C
maxD=int(B/D)*D
maxCD=int(B/CD)*CD
minC=0
minD=0
minCD=0
if A%C==0:
    minC=A
else:
    minC=int((A/C)+1)*C
if A%D==0:
    minD=A
else:
    minD=int((A/D)+1)*D
if A%CD==0:
    minCD=A
else:
    minCD=int((A/CD)+1)*CD

Ccount=int((maxC-minC)/C)+1
Dcount=int((maxD-minD)/D)+1
CDcount=int((maxCD-minCD)/CD)+1
print(B-A+1-Ccount-Dcount+CDcount)

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())
CD=lcm(C,D)
maxC=int(B/C)*C
maxD=int(B/D)*D
maxCD=int(B/CD)*CD
minC=(int(A/C)+1)*C
minD=(int(A/D)+1)*D
minCD=(int(A/CD)+1)*CD
Ccount=int((maxC-minC)/C)+1
Dcount=int((maxD-minD)/D)+1
CDcount=int((maxCD-minCD)/CD)+1
print(B-A+1-Ccount-Dcount+CDcount)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int, input().split())
import math
n1=math.ceil(a/min(c,d))
if a<=min((c,d))*n1<=b:
    l1=(b-min((c,d))*n1)//min((c,d))+1
else: l1=0
  
n2=math.ceil(a/max(c,d))
if a<=max((c,d))*n2<=b:
    l2=(b-max((c,d))*n2)//max((c,d))+1
else: l2=0

import fractions
lcm=(c*d)//fractions.gcd(c, d)
n3=math.ceil(a/lcm)
if a<=lcm<=b:
    l3=(b-lcm)*n3//lcm+1
else: l3=0

ans=(b-a+1)-(l1+l2-l3)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a, b, c, d = map(int, input().split())
list1 = []
for i in range(a, b+1):
    if (i%c==0)&(i%d==0):
        list1.append(i)
print(len(list1))

Submission status: Wrong Answer

Solution code:
def GCD(s, t):
    if s < t:
        s, t = t, s
    if t == 0:
        return s
    else:
        return GCD(t,s%t)

A, B, C, D = map(int, input().split())
E = C*D // GCD(C,D)
x = B // C - A // C
y = B // D - A // D
z = B // E - A // E
print(B-A-x-y+z+1)

Submission status: Wrong Answer

Solution code:
import math
data = input().split()#lines[0]つまり１行目をスペースで区切る.dataは配列
A = int(data[0])
B = int(data[1])
C = int(data[2])
D = int(data[3])

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

X = math.floor(B/C)
Y = math.floor(B/D)
l = C*D/gcd(C,D)
Z = math.floor(B/l)

x = math.floor((A-1)/C)
y = math.floor((A-1)/D)
z = math.floor((A-1)/l)

b = B - X - Y + Z
a = A-1 - x - y + z

ans = b - a
print(ans)

Submission status: Wrong Answer

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

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

count = 0
lcm = C*D / gcd(C,D)


print(B - B//C - B//D + B//lcm - (A - 1 - (A-1)//C - (A-1)//D + (A-1)//lcm))

Submission status: Wrong Answer

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

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

count = 0
lcm = C*D / gcd(C,D)


print(B - B//C - B//D + B//lcm - (A - (A-1)//C - (A-1)//D + (A-1)//lcm))

Submission status: Wrong Answer

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

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

count = 0
len = B-A+1

count += math.floor(B/C)
count -= math.floor((A-1)/C)
count += math.floor(B/D)
count -= math.floor((A-1)/D)

lcm = C*D / gcd(C,D)
count -= math.floor(B/lcm)
count += math.floor((A-1)/lcm)

print(len - count)

Submission status: Wrong Answer

Solution code:
def s_y_n(x, y):
    if y == 0:
        return x
    else:
        return s_y_n(y, x % y)


def s_b_n(x, y):
    return x * y // s_y_n(x, y)


a, b, c, d = map(int, input().split())
bc = b // c
ac = (a-1) // c
bd = b // d
ad = (a-1) // d
bco = b // s_b_n(c, d)
aco = (a-a) // s_b_n(c, d)

print((b-a+1) - (bc-ac)-(bd-ad)+(bco-aco))

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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


# CとDの最小公倍数で割り切れる数
lcmCD = lcm(C, D)


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

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

# Cで割り切れる数
divC = B // C - (A-1) // C

# Dで割り切れる数
divD = B // D - (A-1) // D

# CとDの最小公倍数で割り切れる数
lcmCD = lcm(C, D)
divCD = B // lcmCD - A // lcmCD

# CとDの少なくとも一方で割り切れる数
divCorD = divC + divD - divCD

# AからBまでの数
AB = B - A + 1

print(AB - divCorD)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

# Cで割り切れる数
divC = B // C - (A-1) // C

# Dで割り切れる数
divD = B // D - (A-1) // D

# CとDの最小公倍数で割り切れる数
divCD = B // lcm(C, D) - A // lcm(C, D)

# CとDの少なくとも一方で割り切れる数
divCorD = divC + divD - divCD

# AからBまでの数
AB = B - A + 1

print(AB - divCorD)

Submission status: Wrong Answer

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

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

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

print(int((b - a + 1) - (i + j - k)))

Submission status: Wrong Answer

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

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

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

print((b - a + 1) - (i + j - k))

Submission status: Wrong Answer

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

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

print((b - a + 1) -(i + j - k))

Submission status: Wrong Answer

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

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

print(i, j, k)
print((b - a + 1) -(i + j - k))

Submission status: Wrong Answer

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

i = b//c - a//c
j = b//d - a//d
k = b//(c*d) - a//(c*d)

print((b - a + 1) -(i + j - k))

Submission status: Wrong Answer

Solution code:
import fractions

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


c_and_d=C*D
#CとDの最小公倍数を求める
lcm = int(C*D/fractions.gcd(C,D))


count_C =0
count_D =0
count_C_and_D =0

count_C = int(B/C)-int((A-1)/C)
count_D = int(B/D)-int((A-1)/D)
count_C_and_D = int(B/lcm)-int((A-1)/lcm)

print(int((B-A+1) -(count_C + count_D - count_C_and_D)))

Submission status: Wrong Answer

Solution code:
import fractions

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


c_and_d=C*D
#CとDの最小公倍数を求める
lcm = int(C*D/fractions.gcd(C,D))


count_C =0
count_D =0
count_C_and_D =0

count_C = int(B/C)-int((A-1)/C)
count_D = int(B/D)-int((A-1)/D)
count_C_and_D = int(B/lcm)-int((A-1)/lcm)

print((B-A+1) -(count_C + count_D - count_C_and_D))

Submission status: Wrong Answer

Solution code:
import fractions

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

A = A-1
c_and_d=C*D
#CとDの最小公倍数を求める
lcm = int(C*D/fractions.gcd(C,D))
# print('最小公倍数:',lcm)

count_C =0
count_D =0
count_C_and_D =0

count_C = int(B/C)-int(A/C)
count_D = int(B/D)-int(A/D)
count_C_and_D = int(B/lcm)-int(A/lcm)
A = A+1
print((B-A+1) -(count_C + count_D - count_C_and_D))

Submission status: Wrong Answer

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

A = A-1
c_and_d=C*D
#CとDの最小公倍数を求める
lcm =1
# print('最小公倍数:',lcm)

count_C =0
count_D =0
count_C_and_D =0

count_C = int(B/C)-int(A/C)
count_D = int(B/D)-int(A/D)
count_C_and_D = int(B/lcm)-int(A/lcm)
A = A+1
print((B-A+1) -(count_C + count_D - count_C_and_D))

Submission status: Wrong Answer

Solution code:
import fractions

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

a2 = a - 1

num1 = int(b / d) + int(b / c) - int(b / (c * d / fractions.gcd(c, d)))
num2 = int(a2 / d) + int(a2 / c) - int(a2 / (c * d / fractions.gcd(c, d)))

ans = (b - a2) - (num1 - num2)

print(ans)

Submission status: Wrong Answer

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

ans = []

line = []
for i in range(a, b + 1):
	if i % c != 0:
		line.append(i)
		
for i in range(len(line)):
	if i % d != 0:
		ans.append(i)
		
print(len(ans))

Submission status: Wrong Answer

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

for i in range(a, b):
    if i%c != 0:
        if i%d !=0:
            print(i)

Submission status: Wrong Answer

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

for i in range(a, b):
    if i%c != 0 and i%d != 0:
        print(i )

Submission status: Wrong Answer

Solution code:
import fractions

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

print((B//C+B//D-B//lcm) - (((A-1)//C+(A-1)//D-(A-1)//lcm)))

Submission status: Wrong Answer

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

print(b - a - int(b / c) + int(b / d) - int(b / (c * d)) - int(a / c) + int(a / d) - int(a / (c * d)))

Submission status: Wrong Answer

Solution code:
import fractions

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

divc = B//C - (A-1)//C
divd = B//D - (A-1)//D
lcm = C*D // fractions.gcd(C, D)
divgcd = B//lcm - A//lcm

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

Submission status: Wrong Answer

Solution code:
import math


def lem(A, B):
    AB = A * B
    while B != 0:
        A, B = B, A % B
    return AB // A


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


bsep = (b // c) + (b // d) - (b // lem(c, d))
asep = (a-1) // c + (a-1) // d - (a-1) // lem(c, d)

ans = b - (a+1) - bsep + asep
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    while y > 0:
        x, y = y, x%y
    return x

A,B,C,D = map(int, input().split())
B_C = B // C
B_D = B // D
g = gcd(C,D)
l = C * D / g
duplicate_B = B // l
answer_B = B - B_C - B_D + duplicate_B

A_C = (A - 1) // C
A_D = (A - 1) // D
duplicate_A = (A - 1) // l
answer_A = (A - 1) - A_C - A_D + duplicate_A
print(int(answer_B - answer_A))

Submission status: Wrong Answer

Solution code:
import sys
import fractions
input = sys.stdin.readline
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)


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


print(ans)

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())
re=[]
cd=lcm(c, d)

cc=int(b/c) - int((a-1)/c)
dc=int(b/d) - int((a-1)/d)
cdc=int(b/cd) - int((a-1)/cd)

print(b-a+1-cc-dc+cdc)

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())
re=[]
cd=lcm(c, d)

cc=int(b/c) - int(a/c)
dc=int(b/d) - int(a/d)
cdc=int(b/cd) - int(a/cd)

print(b-a-cc-dc+cdc)

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())
re=[]
cd=lcm(c, d)

cc=int(b/c - a/c)
dc=int(b/d - a/d)
cdc=int(b/cd - a/cd)

print(b-a-cc-dc+cdc)

Submission status: Wrong Answer

Solution code:
import fractions

d = [int(x) for x in input().split()]
lcm = int(d[2] * d[3] / fractions.gcd(d[2], d[3]))
b = d[1] - int(d[1] / d[2]) - int(d[1] / d[3]) + int(d[1] / lcm)
a_1 = d[0] - 1
a = a_1 - int(a_1 / d[2]) - int(a_1 / d[3]) + int(a_1 / lcm)
print(b - a)

Submission status: Wrong Answer

Solution code:
import fractions

d = [int(x) for x in input().split()]
lcm = d[2] * d[3] / fractions.gcd(d[2], d[3])
b = d[1] - int(d[1] / d[2]) - int(d[1] / d[3]) + int(d[1] / lcm)
a_1 = d[0] - 1
a = a_1 - int(a_1 / d[2]) - int(a_1 / d[3]) + int(a_1 / lcm)
print(b - a)

Submission status: Wrong Answer

Solution code:
import fractions

d = [int(x) for x in input().split()]

print(d[1] - d[0] + 1 - (int(d[1] / d[2]) - int((d[0] - 1) / d[2]) + int(d[1] / d[3]) - int((d[0] - 1) / d[3]) - int(d[1] / (d[2] * d[3] / fractions.gcd(d[2], d[3])) + int((d[0] - 1) / (d[2] * d[3] / fractions.gcd(d[2], d[3]))))))

Submission status: Wrong Answer

Solution code:
import fractions

d = [int(x) for x in input().split()]
print(d[1] - d[0] + 1 - (int(d[1] / d[2]) - int((d[0] - 1) / d[2]) + int(d[1] / d[3]) - int((d[0] - 1) / d[3]) - int(d[1] / (d[2] * d[3] / fractions.gcd(d[2], d[3]))) - int((d[0] - 1) / (d[2] * d[3]/ fractions.gcd(d[2], d[3])))))

Submission status: Wrong Answer

Solution code:
d = [int(x) for x in input().split()]
print(d[1] - d[0] - (int(d[1] / d[2]) - int(d[0] / d[2]) + int(d[1] / d[3]) - int(d[0] / d[3]) - int(d[1] / (d[2] * d[3])) - int(d[0] / (d[2] * d[3]))))

Submission status: Wrong Answer

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

def eg(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp

    while True:
        c = a % b
        if c == 0:
            return b
        else:
            b = c

g = eg(C, D)
l = C*D // g

countB = B - (B // C + B // D) + B // l
countA = (A-1) - ((A-1) // C + (A-1) // D) + (A-1) // l

print(countB - countA)

Submission status: Wrong Answer

Solution code:
# a ~ bでcの倍数の個数を返す
def count_maltiple(a, b, c):
    if a == b:
        if a == b and a%c == 0:
            return 1
        else:
            return 0
    else:
        if a%c == 0:
            st = a
        else:
            st = a + c - a%c

        if (b - b%c) - st < 0:
            return 0
        else:
            return int(((b - b%c) - st)/c + 1)
def gcd( x, y ):
    while y != 0:
        x, y = y, x%y
    return x

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


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

Submission status: Wrong Answer

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

# a ~ bでcの倍数の個数を返す
def count_maltiple(a, b, c):
    if a%c == 0:
        st = a
    else:
        st = a + c - a%c
    return int (((b - b%c) - st)/c + 1)

print(int(b - a +1 - (count_maltiple(a,b,c) + count_maltiple(a,b,d) - count_maltiple(a,b,c*d))))

# # 以下だと時間切れ
# for i in range(a, b+1):
#     if i%c == 0 and i%d == 0:
#           cnt += 1
# print(cnt)

Submission status: Wrong Answer

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

# a ~ bでcの倍数の個数を返す
def count_maltiple(a, b, c):
    if a%c == 0:
        st = a
    else:
        st = a + c - a%c
    return ((b - b%c) - st)/c + 1

print(int(b - a +1 - (count_maltiple(a,b,c) + count_maltiple(a,b,d) - count_maltiple(a,b,c*d))))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def euclid(a, b):
    if a > b:
        large = a
        small = b
    else:
        large = b
        small = a

    while small != 0:
        r = large % small
        large = small
        small = r

    return large


def solve(inputs):
    [A, B, C, D] = string_to_int(inputs[0])
    cd_gcd = euclid(C, D)
    cd_lcm = (C*D) / cd_gcd

    a_c = (A-1) // C
    a_d = (A-1) // D
    a_cd = (A-1) // cd_lcm

    b_c = B // C
    b_d = B // D
    b_cd = B // cd_lcm

    # 4 - (2+1-0) = 1
    under_a = (A-1) - (a_c + a_d - a_cd)
    # 9 - (4 + 3 - 1) = 3
    under_b = B - (b_c + b_d - b_cd)

    return (under_b - under_a)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

Solution code:

A,B,C,D = list(map(int,input().split()))
def gcd(a, b):
    if (b == 0):
        return abs(a)
    return gcd(b, a % b)
least_common_multiple = C * D / gcd(C, D)
under_B = B - (B // C) - (B // D) + (B // least_common_multiple)
under_A = A - (A // C) - (A // D) + (A // least_common_multiple)
count = under_B - under_A
# print(f"under_B: {under_B}, under_A: {under_A}")
print(count)

Submission status: Wrong Answer

Solution code:
A,B,C,D = list(map(int,input().split()))
if C == 1 or D == 1:
    count = 0
else:
    n_diff_c_multiple = (B // C) - (A // C)
    n_diff_d_multiple = (B // D) - (A // D)
    def gcd(a, b):
        if (b == 0):
            return abs(a)
        return gcd(b, a % b)
    least_common_multiple = C * D / gcd(C, D)
    n_diff_common_multiple = int((B // least_common_multiple) - (A // least_common_multiple))
    count = n_diff_c_multiple + n_diff_d_multiple - n_diff_common_multiple
# print(f"count:{count}")
print(B - A + 1 - count)

Submission status: Wrong Answer

Solution code:
A,B,C,D = list(map(int,input().split()))
n_diff_c_multiple = (B // C) - (A // C)
n_diff_d_multiple = (B // D) - (A // D)
def gcd(a, b):
    if (b == 0):
        return abs(a)
    return gcd(b, a % b)
least_common_multiple = C * D / gcd(C, D)
n_diff_common_multiple = int((B // least_common_multiple) - (A // least_common_multiple))
count = n_diff_c_multiple + n_diff_d_multiple - n_diff_common_multiple
print(B - A + 1 - count)

Submission status: Wrong Answer

Solution code:
def calc_gcd(x,y):
    amari = max(x,y)%min(x,y)
    if amari == 0:
        return min(x,y)
    return calc_gcd(min(x,y), amari)
def calc_scm(x,y,gcd):
    return x*y//gcd

A,B,C,D = list(map(int, input().split()))
scm = calc_scm(C,D,calc_gcd(C,D))
low = (A-1)//C + (A-1)//D - A//scm
high = B//C + B//D - B//scm
print(B - A + 1 - (high - low))

Submission status: Wrong Answer

Solution code:
def calc_gcd(x,y):
    amari = max(x,y)%min(x,y)
    if amari == 0:
        return min(x,y)
    return calc_gcd(min(x,y), amari)
def calc_scm(x,y,gcd):
    return x*y//gcd

A,B,C,D = list(map(int, input().split()))
low = (A-1)//C + (A-1)//D
high = B//C + B//D
scm = calc_scm(C,D,calc_gcd(C,D))
high -= B//(scm)
print(B - A + 1 - (high - low))

Submission status: Wrong Answer

Solution code:
import math

def ceil(x, y):
    res = int(math.ceil(x/y))
    return res if x//y!=0 else 0

A,B,C,D = list(map(int, input().split()))
low = ceil(A,C) + ceil(A,D) + ceil(A, C*D)
high = B//C + B//D + B//(C*D)
print(B - A - (high - low))

Submission status: Wrong Answer

Solution code:
import math
import fractions


def num_div(n, a, b):
    return math.floor(b / n) - math.ceil(a / n) + 1


a, b, c, d = map(int, input().split())
print((b - a + 1) - (
    num_div(c, a, b)
    + num_div(d, a, b)
    - num_div((c * d) // fractions.gcd(c, d), a, b)))

Submission status: Wrong Answer

Solution code:
import math


def num_div(n, a, b):
    return math.floor(b / n) - math.ceil(a / n) + 1


a, b, c, d = map(int, input().split())
print((b - a + 1) - (num_div(c, a, b) + num_div(d, a, b) - num_div(c * d, a, b)))

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

print(x-y-z+w)

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=(a-1)//c
g=b//c
h=(a-1)//d 
k=b//d
l=(a-1)//e
m=b//e

x=(b-a+1)
y=g-f
z=k-h
w=m-l
print(f,g,h,k,l,m)
print(x-y-z+w)