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:
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        a, b = b, a % b
    return a

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

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

count = b // c - a // c
if a % c == 0:
    count += 1

count += b // d - a // d
if a % d == 0:
    count += 1

count -= (b // lcm - a // lcm)


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

Submission status: Wrong Answer

Solution code:
import math


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

    
A, B, C, D = map(int, input().split())  # A以上B以下の整数のうち、CでもDでも割り切れないものの個数

CD_lcm = (C * D) / gcd(C, D)

# B以下の全ての数でCで割れるものの個数hoge
hogeBC = math.floor(B / C)
# A-1以下の全ての数でCで割れるものの個数fuga
fugaA1C = math.floor((A-1) / C)

piyoBD = math.floor(B / D)
toriA1D = math.floor((A-1) / D)


yoshiBCD = math.floor(B / (CD_lcm))
takaA1CD = math.floor((A-1) / (CD_lcm))

# A以上B以下の整数でCで割り切れるものの個数
Ccan = hogeBC-fugaA1C

# A以上B以下の整数でDで割り切れるものの個数
Dcan = piyoBD - toriA1D

# A以上B以下の整数でCでもDでも割り切れるものの個数
CDcan = yoshiBCD - takaA1CD

print((B-(A-1)) - (Ccan+Dcan-CDcan))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A,B,C,D = map(int, input().split())
cnt = 0
x = (A-1) // C
xx = B // C
y = A // D
yy = (B-1) // D
E = C*D / gcd(C,D)
z = (A-1) // E
zz = B // E
tmp = xx-x + yy-y - (zz-z)
print(int(B-A - tmp))
# print(B-A, xx-x,yy-y,zz-z, tmp, cnt)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int, input().split())
ans=B-A+1
E=C*D

if A%C==0:
    nC_initial=A//C
else:
    nC_initial=A//C+1
    
if A%D==0:
    nD_initial=A//D
else:
    nD_initial=A//D+1

    
if A%E==0:
    nE_initial=A//E
else:
    nE_initial=A//E+1
    
nC_final=B//C
nD_final=B//D
nE_final=B//E
if nE_final<nE_initial:
    nE_final=nE_initial
print(ans,nC_initial,nC_final,nD_initial,nD_final, nE_initial,nE_final)
print(ans-(nC_final-nC_initial+1)-(nD_final-nD_initial+1)+(nE_final-nE_initial+1))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
def gcd(a,b):
  x=max(a,b)
  y=min(a,b)
  if(x%y)==0:
    return y
  else:
    while x%y!=0:
      z=x%y
      x=y
      y=z
    else:
      return z
n=input().rstrip().split(" ")
for i in range(4):
    n[i]=int(n[i])
toc=(n[0]%n[2])
tod=(n[0]%n[3])
tocd=(n[0]%(n[2]*n[3]//gcd(n[2],n[3])))
#print(toc)
#print(tod)
#print(tocd)
d=n[1]-n[0]+1
ans=[d-((d+toc)//n[2]),d-((d+tod)//n[3]),d-((d+tocd)//((n[2]*n[3]//gcd(n[2],n[3]))))]
#print(ans)
print(ans[0]+ans[1]-ans[2])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

l1 = A - (A//C) - (A//D) + (A//(C*D))
l2 = B - (B//C) - (B//D) + (B//(C*D))
print(l2 - l1)

Submission status: Wrong Answer

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

ABc = b // c - (a - 1) // c
ABd = b // d - (a - 1) // d
cd = c * d // fractions.gcd(c, d)
ABcd = b // cd - (a - a) // cd

print(b - a + 1 - (ABc + ABd - ABcd))

Submission status: Wrong Answer

Solution code:
s = input().split()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])
count = 0
C_value = B//C -(A-1)//C
D_value = B//D -(A-1)//D
value = B//(C*D) - (A-1)//(C*D)
print(B-(A-1)-(C_value + D_value - value))

Submission status: Wrong Answer

Solution code:
A, B, C, D =  (int(j) for j in input().split()) 
if C > D:
  d = D
  D = C
  C = D
    
n = B - A + 1
CD = C * D
print( n- ( (B//C - (A-1)//C) + (B//D - (A-1)//D) - (B//CD - (A-1)//CD) ) )

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    token = lines[0].split(" ")
    a = int(token[0])
    b = int(token[1])
    c = int(token[2])
    d = int(token[3])

    return (a, b, c, d)

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c

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

def solve(a, b, c, d):
    
    e = lcm(c, d)

    k = (b - a) // c
    l = (b - a) // d
    m = (b - a) // e
    
    return ((b - a) + 1) - ((k + 1) + (l + 1) - (m + 1))


def main():
    # 出力

    print("%s" % solve(*parse_input()))


if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d=list(map(int,input().split()))
if a!=0:
	a-=1
#a-=1
s=math.floor(b/c)-math.floor(a/c)
e=math.floor(b/d)-math.floor(a/d)
count=b-a-s-e
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
    #return math.floor((x * y) /fractions.gcd(x, y))


com=lcm(c, d)
tmp=math.floor(b/com)-math.floor(a/com)
print(count+tmp)

Submission status: Wrong Answer

Solution code:
from math import ceil

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

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

ans += ceil(B/(C*D) - A/(C*D))

print(ans)

Submission status: Wrong Answer

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

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

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

num = b-a
ans = num - num//c - num//d + num//lcm
#b_num = b - b//c - b//d + b//lcm
#a_num = a - a//c - a//d + a//lcm

#ans = b_num - a_num + 1

print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

ans = 0

if A < C :
    ans += C - A
    A = C

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X >= B :
        return 0
    minX = math.ceil(A / X)
    maxX = math.floor(B / X)

    return maxX - minX + 1

# 最小公倍数
Z = C * D / fractions.gcd(C,D)

ans += B - A + 1 - countX(C) - countX(D) + countX(Z)

print(ans)

Submission status: Wrong Answer

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

cou1=0
cou2=0

y1=int(b/c)
y2=int(b/d)
y3=int(b/lcm)
cou1=b-(y1+y2-y3)

x1=int((a-1)/c)
x2=int((a-1)/d)
x3=int((a-1)/lcm)
cou2=(a-1)-(x1+x2-x3)

print(cou1-cou2)

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
amari1 = A % C
F = hani + amari1
Cnum = int(F / C)
amari2 = A % D
G = hani + amari2
Dnum = int(G / D)
saisyoukoubai = int(C * D / saidaikouyaku(C, D))
amari3 = A % saisyoukoubai
H = hani + amari3
koubainum = int(H / saisyoukoubai)
print(hani - Cnum - Dnum + koubainum)

Submission status: Wrong Answer

Solution code:
import fractions
from math import ceil, floor
def lcm(x, y):
  return (x * y) // fractions.gcd(x, y)
A,B,C,D = map(int, input().split())
n = B-A+1
r = floor(B/C) - ceil(A/C) + 1 + floor(B/D) - ceil(A/D) + 1 - (floor(B/lcm(C,D)) - ceil(A/lcm(C,D)) + 1)
print(n-r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
gcd = 0
if C>D:
  big = C
  small = D
else:
  big = C
  small = D
GCDa = big
while GCDa != 0:
  GCD = GCDa
  tmp = small
  small = big%small
  big = tmp
  GCDa = small
if C == D:
  gcd = C
if GCD == 1:
  ans = B-A+1-((B//C-(A-1)//C)+(B//D-(A-1)//D)-int(int(B/C)//D-(int(A-1)/B)//D))
else:
  gcd = C*D/GCD
  ans = int(B-A+1-((B//C-(A-1)//C)+(B//D-(A-1)//D)-int(int(B//gcd)-int((A-1)//gcd))))
print(ans)

Submission status: Wrong Answer

Solution code:
import math

a,b,c,d =(int(x) for x in input().split())


if a % c == 0:
    canC = math.ceil(((b - a + 1) ) / (c ))
else:
    canC = math.ceil(((b - a + 1) -((c)-a%(c)) ) / (c ))

if a % d == 0:
    canD = math.ceil(((b - a + 1) ) / (d ))
else:
    canD = math.ceil(((b - a + 1) -((d)-a%(d)) ) / (d ))

if a % (c*d) == 0:
    canCD = math.ceil(((b - a + 1) ) / (c*d ))
else:
    canCD = math.ceil(((b - a + 1) -((c*d)-a%(c*d)) ) / (c*d ))

# print(((c*d)-a%(c*d)))
# print(canC,canD,canCD)
print(int(b - a + 1 - (canC + canD - canCD)))

Submission status: Wrong Answer

Solution code:
import fractions

def calcA(a,b):
    if (a / b) != (a // b):
        return a // b + 1
    else:
        return a // b 


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

a1 = calcA(a,c)

a2 = b // c
a3 = a2 - a1 + 1

b1 = calcA(a,d)

b2 = b // d
b3 = b2 - b1 + 1

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

x1 = calcA(a,x)
x2 = b // x
x3 = x2 - x1 + 1

p = b - a + 1
q = a3 + b3 - x3

print(p - q)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import fractions
def lcm(a,b):
    return a * b // fractions.gcd(a,b)
A,B,C,D = [int(x) for x in stdin.readline().rstrip().split()]
div_C = (B // C) - ((A-1) // C)
div_D = (B // D) - ((A-1) // D)
div_lcm = (B // lcm(C,D)) - (A // lcm(C,D))
ans = B - A  - div_C - div_D + div_lcm + 1
print(ans)

Submission status: Wrong Answer

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


def solve(a, b, c, d):
    def how_many(to, divide):
        n = to // divide
        return n
    count_by_c = how_many(b, c) - how_many(a - 1, c)
    count_by_d = how_many(b, d) - how_many(a - 1, d)
    count_by_cd = how_many(b, c * d) - how_many(a - 1, c * d)
    result = b - a + 1 -(count_by_c + count_by_d - count_by_cd)
    return result

def main():
    a, b, c, d = input_from_console()
    print(solve(a, b, c, d))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Wrong Answer

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

cou1=0
cou2=0

y1=int(b/c)
y2=int(b/d)
y3=int(b/lcm)
cou1=b-(y1+y2-y3)

x1=int((a-1)/c)
x2=int((a-1)/d)
x3=int((a-1)/lcm)
cou2=(a-1)-(x1+x2-x3)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A,B,C,D = map(int, input().split())
cnt = 0
x = (A-1) // C
xx = B // C
y = A // D
yy = (B-1) // D
E = C*D / gcd(C,D)
z = A // E
zz = B // E
tmp = xx-x + yy-y - (zz-z)
print(int(B-A - tmp))
# print(B-A, xx-x,yy-y,zz-z, tmp, cnt)

Submission status: Wrong Answer

Solution code:
def main():

    # 1 <= a <= b <= 10^18
    # 1 <= c,d <= 10^9

    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)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#入力取得
A, B, C, D = map(int, input().split())


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


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



lcm = lcm(C ,D)


num_all = B - A + 1


ans = 0

z_a_c = int((A-1) / C)
z_b_c = int(B / C)

z_a_b_c = z_b_c - z_a_c


z_a_d = int((A-1) / D)
z_b_d = int(B / D)

z_a_b_d = z_b_d - z_a_d

z_a_l = int((A-1) / lcm)
z_b_l = int(B / lcm)

z_a_b_l = z_b_l - z_a_l


ans = num_all - z_a_b_c - z_a_b_d + z_a_b_l


print(ans)

Submission status: Wrong Answer

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

bc = b/c
bd = b/d
saisyounum = c * d / fractions.gcd(c, d)
anum = int(ac+ad-a/saisyounum)
bnum = int(bc+bd-b/saisyounum)
print((b-bnum)-(a-anum)+1)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
if A%C==0 and A%D==0:
    C_div = (B-A+1)//C + 1
else:
    C_div = (B-A+1)//C
if B%C==0 and B%D==0:
    D_div = (B-A+1)//D + 1
else:
    D_div = (B-A+1)//D
if A%(C*D) == 0 and B%(C*D) == 0:
    CD_div = (B-A+1)//(C*D) + 1
else:
    CD_div = (B-A+1)//(C*D)
ans = (B-A+1) - C_div -D_div + CD_div

Submission status: Wrong Answer

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


def solve(a, b, c, d):
    def how_many(to, divide):
        n = to // divide
        return n
    count_by_c = how_many(b, c) - how_many(a - 1, c)
    count_by_d = how_many(b, d) - how_many(a - 1, d)
    count_by_cd = how_many(b, c * d) - how_many(a - 1, c * d)
    print(count_by_c, count_by_d, count_by_cd)
    result = b - a + 1 -(count_by_c + count_by_d - count_by_cd)
    return result

def main():
    a, b, c, d = input_from_console()
    print(solve(a, b, c, d))


if __name__ == "__main__":
    import sys

    if sys.gettrace():  # Check if the python interpreter is in debug mode or not.
        check_cases()
    else:
        main()

Submission status: Wrong Answer

Solution code:
import fractions

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


#A-BまでのCの個数

Cnum=int((B-A+1)//C)+ ((B-A+1)%C >= (C-A%C))
Dnum=int((B-A+1)//D)+ ((B-A+1)%D >= (D-A%D))

CD= int(C*D/(fractions.gcd(C,D)))

CDnum=int((B-A+1)//CD)+ ((B-A+1)%CD >= (CD-(A%CD)))

print(B-A+1-Cnum-Dnum+CDnum)

Submission status: Wrong Answer

Solution code:
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 lcm(m, n):
    return int(m * n / gcd(m, n))

a, b, c, d = map(int, input().split())
l = lcm(c, d)
c_num = int(b/c) - int((a-1)/c)
d_num = int(b/d) - int((a-1)/d)
l_num = int(b/l) - int((a-1)/l)
print((b - a + 1) - c_num - d_num + l_num)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
rem = b - a + 1
pattern1 = (rem + (c - 1 - a % c)) // c
pattern2 = (rem + (d - 1 - a % d)) // d
bi = (c * d // fractions.gcd(c, d))
pattern3 = (rem + (bi - 1 - a % bi)) // bi
print(rem - pattern1 - pattern2 + pattern3)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions

A, B, C, D = list(map(int, stdin.readline().split()))
cd = C * D / fractions.gcd(C,D)

Nc = B // C - math.ceil(A / C) + 1
Nd = B // D - math.ceil(A / D) + 1
Ncd = B // cd - math.ceil(A / cd) + 1

print(int(B-A+1-(Nc+Nd-Ncd)))

Submission status: Wrong Answer

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


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


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

first_c = c * (a // c + 1)
if a % c == 0:
    first_c -= c
last_c = c * (b // c)

first_d = d * (a // d + 1)
if a % d == 0:
    first_d -= d
last_d = d * (b // d)

cd = lcm(c, d)
first_cd = cd * (a // cd + 1)
if a % cd == 0:
    first_d -= cd
last_cd = cd * (b // cd)

cnum = 0
dnum = 0
cdnum = 0

if first_c <= b:
    cnum = (last_c - first_c) // c + 1

if first_d <= b:
    dnum = (last_d - first_d) // d + 1

if first_cd <= b:
    cdnum = (last_cd - first_cd) // cd + 1

total = cnum + dnum - cdnum
print(b - a + 1 - total)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
inputs = [int(s) for s in input().split()]
a = inputs[0]
b = inputs[1]
c = inputs[2]
d = inputs[3]
count = 0
minCD = min(c, d)
maxCD = max(c, d)

x0 = b-a+1
x1 = b//minCD - (a-1)//minCD
x2 = b//maxCD - (a-1)//maxCD
lcm = minCD * maxCD // gcd(minCD, maxCD)
x3 = b//lcm - (a-1)//lcm
print(x0, x1, x2, x3)
if maxCD % minCD == 0:
    print(x0-x1)
else:
    print(x0-(x1+x2-x3))

Submission status: Wrong Answer

Solution code:
import math
import fractions
A, B, C, D = map(int, input().split())
gcd = fractions.gcd(C, D)
ans = (B-A) - (B-A) // C - (B-A) // D + (B-A) // ((C*D) // gcd)
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

E=C*D//gcd(C,D)
total=0
if A%C==0 and A>=C:
    total += B//C-A//C+1
else:
    total += B // C - A // C

if A%D==0 and A>=D:
    total += B//D-A//D+1
else:
    total += B // D - A// D

if A%E==0:
    total = total- B//E-A//E+1
else:
    total = total - B // E - A // E

print(B-A+1-total)

Submission status: Wrong Answer

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

x = c
y = d
while y:
    x, y = y, x % y
gcd = x
lcm = c * d // gcd
if a != b:
    sc = (b // c - (a-1) // c)
    sd = (b // d - (a-1) // d)
    slcm = b // lcm - a // lcm
    print(b-a+1 - sc - sd + slcm)
else:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

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

def lcm(a, b):
    return a * b / gcd(a, b)
A, B, C, D = map(int, input().split())
diff = B - A
ret = 0
if C == 1 or D == 1:
    print(0)
else:
    ret += diff // C
    if A % C == 0 and B % C == 0:
        ret += 1
    ret += diff // D
    if A % D == 0 and B % D == 0:
        ret += 1
    a = diff // int(lcm(C, D))
    print(diff-ret+a)

Submission status: Wrong Answer

Solution code:
import math

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

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

# cの倍数の数
cCount = math.floor(b / c) - math.ceil(a / c) + 1
dCount = math.floor(b / d) - math.ceil(a / d) + 1

lcm = int(c * d / gcd(c, d))
lcmCount = math.floor(b / lcm) - math.ceil(a / lcm) + 1

print(b - a + 1 - (cCount + dCount - lcmCount))

Submission status: Wrong Answer

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

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

CD = C*D/gcd(C,D)

Ac = int((A-1)/C)
Ad = int((A-1)/D)
Acd = int((A-1)/(CD))
a = (A-1)-(Ac+Ad-Acd)

Bc = int(B/C)
Bd = int(B/D)
Bcd = int(B/(CD))
b = B-(Bc+Bd-Bcd)

print(b-a)

Submission status: Wrong Answer

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

ans = 0

c_n_min = math.ceil(A / C)
c_n_max = math.floor(B / C)
c_n = c_n_max - c_n_min + 1

d_n_min = math.ceil(A / D)
d_n_max = math.floor(B / D)
d_n = d_n_max - d_n_min + 1

cd = C * D // fractions.gcd(C,D)
cd_n_min = math.ceil(A / cd)
cd_n_max = math.floor(B / cd)
cd_n = cd_n_max - cd_n_min + 1

ans = (B - A + 1) - (c_n + d_n - cd_n)
print(ans)

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
cnt = 0
C_D = round((B - A + 1) / (C*D))
c = round((B - A + 1) / C)
d = round((B - A + 1) / D)
m = c + d - C_D
ans = (B - A + 1) - m
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
A, B, C, D = map(int, input().split())

num_div_C = math.floor(B / C) - math.floor(A / C) + 1
num_div_D = math.floor(B / D) - math.floor(A / D) + 1
num_div_CD = math.floor(B / (C * D)) - math.floor(A / (C * D)) + 1

print(B - A + 1 - (num_div_C + num_div_D - num_div_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

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

ac=int(A/C)
bc=int(B/C)
ad=int(A/D)
bd=int(B/D)
acd=int(A/lcm(C,D))
bcd=int(B/lcm(C,D))

if A%C==0:
    c_div=bc-ac+1
else:
    c_div = bc - ac
if B%C==0:
    d_div=bd-ad+1
else:
    d_div = bd - ad
if B%lcm(C,D)==0:
    cd_div=bcd-acd+1
else:
    cd_div = bcd - acd

print(B-A+1-c_div-d_div+cd_div)

Submission status: Wrong Answer

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

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

    end = (B // mod) * mod

    return (end - start) / mod +1

ans  =(B-A+1)  - (num_of_mod0(C) + num_of_mod0(D) - num_of_mod0(C*D))

print(int(ans))

Submission status: Wrong Answer

Solution code:
A, B, C, D =  (int(j) for j in input().split()) 
n = B - A + 1
CD = C * D
print( n- ( (B//C - (A-1)//C) + (B//D - (A-1)//D) - (B//CD - (A-1)//CD) ) )

Submission status: Wrong Answer

Solution code:
A,B,C,D = map(int,input().split())
gcd = 0
if C>D:
  big = C
  small = D
else:
  big = C
  small = D
GCDa = big
while GCDa != 0:
  GCD = GCDa
  tmp = small
  small = big%small
  big = tmp
  GCDa = small
if GCD == 1:
  ans = B-A+1-((B//C-(A-1)//C)+(B//D-(A-1)//D)-int(int(B/C)//D-(int(A-1)/B)//D))
else:
  gcd = C*D/GCD
  ans = int(B-A+1-((B//C-(A-1)//C)+(B//D-(A-1)//D)-int(int(B//gcd)-int((A-1)//gcd))))
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

Submission status: Wrong Answer

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

under_c = (A - 1) // C
under_d = (A - 1) // D
under_cd = (A - 1) // (C * D)

top_c = B // C
top_d = B // D
top_cd = B // (C * D)

ans = B - A + 1 - (top_c - under_c) - (top_d - under_d) + (top_cd - under_cd)

print(ans)

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

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

perCfromA = (A-1)//C
perDfromA = (A-1)//D
perCDfromA = (A-1)//(C*D)


perCfromB = B//C
perDfromB = B//D
perCDfromB = B//(C*D)

warikire = (perCfromB + perDfromB -perCDfromB) - (perCfromA + perDfromA -perCDfromA)
warikirenai = dis -warikire
print(warikirenai)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

cnt = int(0)

for i in [c, d]:
    t4 = a // i
    if a % i == 0:
        t1 = t4
    else:
        t1 = t4+1
    t2 = b // i

    cnt += int(t2 - t1 + 1)

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

i = lcm
t4 = a // i
if a % i == 0:
    t1 = t4
else:
    t1 = t4 + 1
t2 = b // i

cnt -= int(t2 - t1 + 1)

print(b - a + 1 - cnt)

Submission status: Wrong Answer

Solution code:
a,b,c,d=list(map(int,input().split(" ")))
Ncd=int(b/c/d)-int(a/c/d)
Nc=int(b/c)-int(a/c)
Nd=int(b/d)-int(a/d)
print(b-a-(Nc+Nd-Ncd))

Submission status: Wrong Answer

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

a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
x=a+a%c
y=a+a%d
e=lcm(c,d)
z=a+a%e
x2=(b-x)//c+1
y2=(b-y)//d+1
z2=(b-z)//e+1
print(b-a-x2-y2+z2+1)

Submission status: Wrong Answer

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

if c == 1 or d == 1:
  print(0)
  exit()

c_left = max(0, [a // c - 1, a // c][a % c != 0])
c_right = b // c

c_number = c_right - c_left

d_left = max(0,[a // d - 1, a // d][a % d != 0])
d_right = b // d

d_number = d_right - d_left
cdgcd = (c * d) // fractions.gcd(c, d)

try:
    cd_left = max(0,[a // (cdgcd - 1), a // (cdgcd)][a % (cdgcd) != 0])
    cd_right = b // (cdgcd)
    cd_number = cd_right - cd_left
except:
    pass
  
print(b - a + 1 -  (c_number + d_number - cd_number))

Submission status: Wrong Answer

Solution code:
import fractions

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

    def num_of_multiples(st, ed, m):
        a = st % m
        a0 = st + (m - a)
        if a0 > ed:
            return 0
        if a == 0:
            a0 = st
        b = ed % m
        b0 = ed - b
        num = (b0 - a0)
        if num % m != 0:
            raise Exception()
        return (b0 - a0) // m + 1
    
    nc = num_of_multiples(A, B, C)
    nd = num_of_multiples(A, B, D)
    ncd = num_of_multiples(A, B, C * D // fractions.gcd(C, D))
    print(B - A + 1 - (nc + nd - ncd))


main()

Submission status: Wrong Answer

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


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


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

first_c = c * (a // c + 1)
if a % c == 0:
    first_c -= c
last_c = c * b // c
first_d = d * (a // d + 1)
if a % d == 0:
    first_d -= d
last_d = d * b // d
cd = lcm(c, d)
first_cd = cd * (a // cd + 1)
if a % cd == 0:
    first_d -= cd
last_cd = cd * b // cd

cnum = 0
dnum = 0
cdnum = 0

if first_c <= b:
    cnum = (last_c - first_c) // c + 1

if first_d <= b:
    dnum = (last_d - first_d) // d + 1

if first_cd <= b:
    cdnum = (last_cd - first_cd) // cd + 1

total = cnum + dnum - cdnum
print(b - a + 1 - total)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd


def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    a, b, c, d = MAP()
    l=gcd(c,d)*c*d
    kukan = b - a + 1
    ans=kukan-int(kukan/c)-int(kukan/d)+int(kukan/l)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

x = c
y = d
while y:
    x, y = y, x % y
gcd = x
lcm = c * d // gcd
if a != b or True:
    sc = (b // c - (a-1) // c)
    sd = (b // d - (a-1) // d)
    slcm = b // lcm - a // lcm
    print(b-a+1 - sc - sd + slcm)
else:
    if a % c != 0 and a % d != 0:
        print(1)
    else:
        print(0)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

C_count = math.floor(B/C) - math.ceil(A/C) + 1
D_count = math.floor(B/D) - math.ceil(A/D) + 1
both_count = math.floor(B/lcm(C, D)) - math.ceil(A/lcm(C, D)) + 1
# print(C_count)
# print(D_count)
# print(both_count)
if C != D:
  answer = B - A + 1 - (C_count + D_count - both_count)
else: 
  answer = B - A + 1 - (C_count)
print(answer)

Submission status: Wrong Answer

Solution code:
import fractions
import numpy as np
import os
import sys

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

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

A0=int(A/C)
B0=int(B/C)
if(A%C==0):
    B0+=1
C0=B0-A0


A1=int(A/D)
B1=int(B/D)
if(A%D==0):
    B1+=1
D1=B1-A1

A2=int(A/E)
B2=int(B/E)
if(A%E==0):
    B2+=1
E2=B2-A2

if(C==1 or D==1):
    print(0)
else:
    print((B-A+1)-(C0+D1-E2))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
A,B,C,D = map(int, input().split())
cnt = 0
x = A // C
xx = B // C
y = A // D
yy = B // D
E = C*D / gcd(C,D)
z = A // E
zz = B // E
tmp = xx-x + yy-y - (zz-z)
print(int(B-A - tmp + 1))

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())
m = int(c*d/gcd(c,d))
if a%c < b%c:
  xc = (b-a+1)//c
elif a%c > b%c:
  xc = (b-a+1)//c +1
elif a%c == b%c and a%c == 0:
  xc = (b-a+1)//c +1
else:
  xc  = (b-a+1)//c

if a%d < b%d:
  xd = (b-a+1)//d
elif a%d > b%d:
  xd = (b-a+1)//d +1
elif a%d == b%d and a%d == 0:
  xd = (b-a+1)//d +1
else:
  xd  = (b-a+1)//d

if a%m < b%m:
  xm = (b-a+1)//m
elif a%m > b%m:
  xm = (b-a+1)//m +1
elif a%m == b%m and a%m == 0:
  xm = (b-a+1)//m +1
else:
  xm  = (b-a+1)//m

print(b-a+1-xc-xd+xm)