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):
    while b!=0:
        a,b=b,a%b
    return a
a,b,c,d=list(map(int,input().split(" ")))
g=gcd(c,d)
lcm=c*d/g
Ncd=int(b/(lcm))-int(a-1/(lcm))
Nc=int(b/c)-int(a-1/c)
Nd=int(b/d)-int(a-1/d)
print(b-a+1-(Nc+Nd-Ncd))
print(Nc,Nd,Ncd)

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c

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

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

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

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

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

print(c1,d1,e1)

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

Submission status: Wrong Answer

Solution code:
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(int(num))

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

print((B+1-A)-Ccnt-Dcnt+CDcnt)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int, input().split())
x = abs(A-B)//C + 1
y = abs(A-B)//D + 1
if B/((C*D)//fractions.gcd(C,D)) < 1:
    z = 0
else:
    z = abs(A-B)//((C*D)//fractions.gcd(C,D)) + 1
print(B-A+1-x-y+z)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
"""
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
"""
def lcm(x, y):
    return (x * y)//gcd(x, y)

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

A,B,C,D = list(map(int, input().split()))
print(f(B, C, D)-f(A-1, C, D))

Submission status: Wrong Answer

Solution code:
# import math
#
#
inp = input()
split_inp = inp.split()
a_t = int(split_inp[0])
b_t = int(split_inp[1])
c_t = int(split_inp[2])
d_t = int(split_inp[3])
#
#
def gcd(a, b):
    if a < b:
        c = a
        a = b
        b =c
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b


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

def comp(number, a_n, b_n):
    return number - (number // a_n + number // b_n - number // lcm(a_n, b_n))

# print(int(comp(b, c, d)))
print(int(comp(b_t, c_t, d_t) - comp(a_t-1, c_t, d_t)))

# print(lcm(15, 20))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if c!=d:
    
    
    sma=min(c,d)
    big=max(c,d)
    
    while sma!=0 :
        cal=big%sma
        big=sma
        sma=cal
    
    euc=big
    ggg=c*d//euc
    
    #print(euc,ggg)
    
    def  cnt(n,ggg,c,d):
        exc=ggg//c + ggg//d
        if c<ggg or d<ggg:
            exc-=1
        ret=exc*(n//ggg)
        print(ggg,exc,ret)
        remain=n%ggg
        ret+= remain//c + remain//d
        return ret
    
    #print(cnt(b,ggg,c,d))
    #print(cnt(a-1,ggg,c,d))
    
    jog=cnt(b,ggg,c,d)-cnt(a-1,ggg,c,d)
    
    ans=(b-a+1)-jog
    
    print(ans)
    
else:
    jog=(b//c) -((a-1)//c)
    print(b-a+1-jog)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cCnt = (B-A)//C
dCnt = (B-A)//D
cdCnt = (B-A)//(C*D)

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

Submission status: Wrong Answer

Solution code:
import math
import fractions

def main():

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

    count_C,count_D,count_CD = 0,0,0
    CD = C * D / fractions.gcd(C,D)
    print("CD = ", CD)

    for i in range(A,B+1):
        if i%C == 0:
            count_C += (B-i)//C + 1
            break
        else:
            continue

    print("count_C = ", count_C)

    for j in range(A,B+1):
        if j%D == 0:
            count_D += (B-j)//D + 1
            break
        else:
            continue

    print("count_D = ", count_D)

    for k in range(A,B+1):
        if k%CD == 0:
            count_CD += (B-k)//CD + 1
            break
        else:
            continue

    print("count_CD = ", count_CD)

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

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

# Cで割り切れる数
div_c_min = math.ceil(A/C)
div_c_max = math.floor(B/C)
div_c_num = div_c_max - div_c_min + 1
#print(div_c_min, div_c_max)
#print(div_c_num)

# Dで割り切れる数
div_d_min = math.ceil(A/D)
div_d_max = math.floor(B/D)
div_d_num = div_d_max - div_d_min + 1
#print(div_d_min, div_d_max)
#print(div_d_num)

# 最大公約数
def gcd(m, n):
  x = max(m, n)
  y = min(m, n)
  while x%y != 0:
    z = x % y
    x = y
    y = z
  else:
    return y

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

# CとDの公倍数で割り切れる数
div_cd_min = math.ceil(A / lcm(C, D))
div_cd_max = math.floor(B / lcm(C, D))
div_cd_num = div_cd_max - div_cd_min + 1
#print(div_cd_min, div_cd_max)
#print(div_cd_num)

numAtoB = B - A + 1
ans = numAtoB - (div_c_num + div_d_num - div_cd_num)
if ans >= 0:
    print(ans)
else:
    print(0)

Submission status: Wrong Answer

Solution code:
a, b, c, d=map(int, input().split())
count_cd=0
count_c=0
count_d=0
X=b-a+1
for i in range(a, b+1):
    if i%c==0 & i%d==0:
        count_cd+=1
    elif i%c==0 & i%d!=0:
        count_c+=1
    elif i%c!=0 & i%d==0:
        count_d+=1

print(X-count_c-count_d+count_cd)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
#a,bの最大公約数
def calcGCD(a, b):
    while b:
        a, b = b, a % b
    return a

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

def countNum(ab, c, d, lcm):
    return int(ab / c) + int(ab / d) - int(ab / lcm)

a, b, c, d = list(map(int, input().split()))
a -= 1
lcm = calcLCM(c, d)
print(b - a - (countNum(b, c, d, lcm) - countNum(a, c, d, lcm)))

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(a, b):
    return a * b // gcd (a, b)

N_C = (B-A) // C
N_D = (B-A) // D
N_CD = (B-A) // lcm(C,D)

ans = (B-A)-N_C-N_D+N_CD
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input=sys.stdin.readline()
a,b,c,d=map(int,input.split())
if c>d:
    m=c
    n=d
else:
    m=d
    n=c
while True:
    t=m%n
    if t==0:
        break
    else:
        m=n
        n=t
cd=c*d/n
ans_1=int(b/c)-int((a-1)/c)
ans_2=int(b/d)-int((a-1)/d)
ans_3=int(b/cd)-int((a-1)/cd)
print(b-a+1-ans_1-ans_2+ans_3)

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

if d > c:
    c, d = d, c

cc = 0
for i in range(a, b):
    if(i%c == 0):
        continue
    if(i%d == 0):
        continue
    cc += 1
print(cc)

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

lcm = C*D/gcd(C,D)
b_s = int(B/C) + int(B/D) - int(B/lcm)
a_s = int((A-1)/C) + int((A-1)/D) - int((A-1)/lcm)
print(B-A+1-(b_s - a_s))

Submission status: Wrong Answer

Solution code:
def function(num_from, num_to , num):
	return (num_to // num) - ((num_from-1)// num)

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

result = (b - a + 1) - ((function(a,b,c) + function( a ,b, d) - function(a,b, c*d)))

print(result)

Submission status: Wrong Answer

Solution code:
import math
import fractions
A, B, C, D = map(int, input().split())
if B < C and B < D:
    ans = B-A+1
else:
    gcd = fractions.gcd(C, D)
    # gcd = math.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:
from fractions import gcd
A, B, C, D = map(int, input().split())

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

def func(num, A, B):
    if A % num == 0:
        return B // num - A // num + 1
    else:
        return B // num - A // num

first = func(C, A, B)
second = func(D, A, B)
third = func(LCM, A, B)

total = first + second - third

print(int(B - A - total + 1))

Submission status: Wrong Answer

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


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

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

def Ndivingcd(x, y, i):
    Ntoi   = i - (int)(i/x) - (int)(i/y) +1
    return Ntoi

CDgcd = lcm(C,D)
Ningcd = CDgcd - (int)(CDgcd/C) - (int)(CDgcd/D) +1
Nloop = math.floor(B / CDgcd)-math.floor(A / CDgcd)
firstgcd = math.floor(A / CDgcd)*CDgcd
lastgcd  = math.floor(B / CDgcd)*CDgcd
NdivtoA = Ndivingcd(C,D,A-firstgcd-1)
NdivtoB = Ndivingcd(C,D,B-lastgcd)
N = Nloop*Ningcd+NdivtoB-NdivtoA
print(N)

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
if z>=b:
    print(b-a-x2-y2)
else:
    print(b-a+1-x2-y2+z2)

Submission status: Wrong Answer

Solution code:
# 逆に公倍数を引く。B-A+1-(Cの倍数の数+Dの倍数の数-CとDの公倍数の数)
# にぶたんで倍数の数を判定
# 1WA

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


def lcd(x, y):
    if x > y:
        return lcd(y, x)
    while x > 0:
        x, y = y % x, x
    return y


def gcm(x, y):
    return (x * y)/lcd(x, y)


def lower_bound(x, y):
    l, r = 0, 10 ** 18 * 1
    while l < r:
        mid = (l + r) // 2
        if x*mid > y:
            r = mid
        else:
            l = mid + 1
    return r


def upper_bound(x, y):
    l, r = 0, 10 ** 18 + 1
    while l < r:
        mid = (l + r) // 2
        if x*mid >= y:
            r = mid
        else:
            l = mid + 1
    return r


z = gcm(c, d)
c_l, c_r = upper_bound(c, a), upper_bound(c, b)
if c_r*c > b:
    c_r -= 1
d_l, d_r = upper_bound(d, a), upper_bound(d, b)
if d_r*d > b:
    d_r -= 1
z_l, z_r = upper_bound(z, a), upper_bound(z, b)
if z_r*z > b:
    z_r -= 1
# print(c_l, c_r, d_l, d_r, z_l, z_r)
print(b-a+1 - ((c_r-c_l+1)+(d_r-d_l+1)-(z_r-z_l+1)))

Submission status: Wrong Answer

Solution code:
number =str(input())
numbers = number.split(" ")
A = int(numbers[0])
B = int(numbers[1])
C = int(numbers[2])
D = int(numbers[3])
list_1 = []
list_2 = []

for i in range(A, B+1):
    if i % C != 0:
        list_1.append(i)
for j in list_1:
    if j % D != 0:
        list_2.append(j)
        
print(list_2)

Submission status: Wrong Answer

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

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

lcm = lcm(C, D)

llcm = math.ceil(A / lcm)
rlcm= math.floor(B / lcm)

lc = math.ceil(A / C)
rc = math.floor(B / C)

ld = math.ceil(A / D)
rd = math.floor(B / D)


nlcm = rlcm-llcm+1
nc = rc - lc + 1
nd = rd - ld + 1

print(B-A+1-nc-nd+nlcm)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
ac = (a-1)//c
ad = (a-1)//d
bc = b//c
bd = b//d
saisyounum = c * d / fractions.gcd(c, d)
checknum = (b//saisyounum)-((a-1)//saisyounum)
ans = int((bc-ac)+(bd-ad)-checknum)
print(b-a-ans+1)

Submission status: Wrong Answer

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

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+1 - tmp))

Submission status: Wrong Answer

Solution code:
# n = int(sys.stdin.readline())
# a, b = map(int, sys.stdin.readline().split())
# c = list(map(int, sys.stdin.readline().split()))
# s = [list(map(int,list(sys.stdin.readline()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a = 100
# b = 0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋め, 小数点出力桁指定時のときの出力
# 000100-0.987654

import math
import sys
import itertools
import queue

mod = 1000000007

def gcd(a,b):
    """Compute the greatest common divisor of a and b"""
    while b > 0:
        a, b = b, a % b
    return a

def lcm(a, b):
    """Compute the lowest common multiple of a and b"""
    return a * b / gcd(a, b)

if __name__ == "__main__":
    A, B, C, D = map(int, sys.stdin.readline().split())
    A = A - 1
    c_div = int(B // C)
    d_div = int(B // D)
    cd_div = int(B // lcm(C, D))

    not_div1 = B - (c_div + d_div -cd_div)

    c_div = int(A // C)
    d_div = int(A // D)
    cd_div = int(A // lcm(C, D))

    not_div2 = A - (c_div + d_div -cd_div)

    print(not_div1 - not_div2)

Submission status: Wrong Answer

Solution code:
import fractions
a,b,c,d = map(int,input().split())
cnt = 0
minc = a // c 
if a % c != 0:
        minc += 1
mind = a // d
if a % d != 0:
        mind += 1
cmul = (b - minc * c) // c + 1
dmul = (b - mind * d) // d + 1
com = c * d / fractions.gcd(c,d)
mincd = a // com
if a % com != 0:
        mincd += 1
cdmul = (b - mincd * com) // com + 1
print(int(b - a + 1 - (cmul + dmul - cdmul)))

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D = map(int, input().split())
x = abs(A-B)//C + 1
y = abs(A-B)//D + 1
if abs(B)//((C*D)//fractions.gcd(C,D)) == 0:
    z = 0
else:
    z = abs(A-B)//((C*D)//fractions.gcd(C,D)) + 1
print(B-A+1-x-y+z)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

def main():
    a,b,c,d = map(int,input().split(" "))
    n = b - a + 1
    cd = int(c * d / gcd(c, d))
    noinclude = int((a-1)/c) + int((a-1)/d) - int((a-1)/cd)
    include = int(b/c) + int(b/d) - int(b/cd) - noinclude
    print(n - include)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
A,B,C,D =  map(int,input().split(" "))
NUM = B
NUM -= int(B / C)
NUM -= int(B / D)
NUM += int(B /(C*D))
#print(NUM)
LNUM = A-1
LNUM -= int((A-1) / C)
LNUM -= int((A-1) / D)
LNUM -= int((A-1) / (C*D))
#print(LNUM)
print(NUM - LNUM)

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)

E = lcm(C, D)

val1 = A // C
val2 = B // C
val3 = A // D
val4 = B // D
val5 = A // E
val6 = B // E

s = B - A + 1

if A % C or A % D:
    print(s - (val2 - val1 + val4 - val3 - (val6 - val5)) - 1)
else:
    print(s - (val2 - val1 + val4 - val3 - (val6 - val5)))

Submission status: Wrong Answer

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

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

a,b,c,d = list(map(int,input().split(" ")))
e = lcm(c,d)

p=a//c
o=b//c
i=a//d
u=b//d
y=a//e
t=b//e

print(b-a+1-(o-p+u-i-t+y))

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)

e=lcm(c,d)


def k(a,b):
    return a//b


ans_h=k(b,c)+k(b,d)-k(b,e)-k(a-1,c)-k(a-1,d)

print(b-a+1-ans_h)

Submission status: Wrong Answer

Solution code:
#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b / gcd(a,b)
a,b,c,d = map(int,input().split())
canC = b//c - (a-1)//c
canD = b//d - (a-1)//d
dbCD = b//lcm(c,d) - (a-1)//lcm(c,d)
print(int((b-a+1) -canC - canD + dbCD))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc131/tasks/abc131_c

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

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

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

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

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

print(c1,d1,e1)

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

Submission status: Wrong Answer

Solution code:
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)
if C == 1 or D == 1:
    print(0)
elif C == D:
    print((B-A+1) - C_div)
elif C%D==0 or D%C==0:
    if C > D:
        print((B-A+1) - D_div)
    else:
        print((B-A+1) - C_div)
else:
    print((B-A+1) - C_div -D_div + CD_div)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
	r = x % y
	while(r != 0) :
		x = y;
		y = r;
		r = x % y;
	
	return y
def lcm(x, y):
    return (x * y) // gcd(x, y)

str = input()
A = int(str.split()[0])
B = int(str.split()[1])
C = int(str.split()[2])
D = int(str.split()[3])

s = B - A + 1
if (A % C == 0) :
	aKc = int(A / C)
else :
	aWc = A / C
	aIc = int(aWc)
	aKc = aIc + 1
bKc = int(B / C)

if (A % D == 0) :
	aKd = int(A / D)
else :
	aWd = A / D
	aId = int(aWd)
	aKd = aId + 1
bKd = int(B / D)

lcm = lcm(C, D)
if (A % lcm == 0) :
	aKcd = int(A / lcm)
else :
	aWcd = A / lcm
	aIcd = int(aWcd)
	aKcd = aIcd + 1
bKcd = int(B / lcm)

print("{}".format(s - (bKc - aKc + 1 + bKd - aKd + 1 - (bKcd - aKcd + 1))))

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()))
    print(solve(*parse_input()))


if __name__ == '__main__':

    main()

Submission status: Wrong Answer

Solution code:
#最大公約数
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
#最小公倍数
def lcm(x,y):
    return (x*y//gcd(x,y))


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

if C==D:
    print(B+1-A-(B//C-A//C)-1)
elif A==C or A==D or B==C or B==D:
    print(B+1-A-(B//C-A//C)-2)
else:
    c = (B+1)//C-A//C
    d = (B+1)//D-A//D
    e = (B+1)//CDlcm-A//CDlcm
    print((B-A+1)-c-d+e)

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
if z>b:
    print(b-a+1-x2-y2)
else:
    print(b-a+1-x2-y2+z2)

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(x, y):
    return (x * y) // gcd(x, y)

allnum =  B -A +1
if A%C==0:
    Csta = A
else:    
    Csta = A + (C-A%C)
if B%C==0:
    Cowa = B
else:    
    Cowa = B -B%C

if A%D==0:
    Dsta = A
else:    
    Dsta = A + (D-A%D)
if B%D==0:
    Dowa = B
else:    
    Dowa = B -B%D     

E = lcm(C, D)
if A%E==0:
    Esta = A
else:    
    Esta = A + (E-A%E)
if B%E==0:
    Eowa = B
else:    
    Eowa = B -B%E     

if A>Csta or B<Csta:
    Cnum = 0
else:
    Cnum = (Cowa-Csta+C)/C

if A>Dsta or B<Dsta:
    Dnum = 0
else:
    Dnum = (Dowa-Dsta+D)/D

if A>Esta or B<Esta:
    Enum = 0
else:
    Enum = (Eowa-Esta+E)/E


num = allnum - Cnum - Dnum + Enum
print(int(num))

Submission status: Wrong Answer

Solution code:
import fractions

parents = list(map(int,input().split(' ')))
All = parents[1] - parents[0]
min_2 = (parents[2]*parents[3]) // fractions.gcd(parents[2], parents[3])
print(All-All//parents[2]-All//parents[3]+All//min_2)

Submission status: Wrong Answer

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

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

a, b, c, d = map(int, input().split())
b1 = b // c
a1 = a // c
b2 = b // d
a2 = a // d
a3 = a // lcm(c,d)
b3 = b // lcm(c,d)
a_ans = a1 + a2 - a3
b_ans = b1 + b2 - b3
diff = b - a + 1
ans = diff - (b_ans - a_ans)
if (lcm(a,b) == a*b):
    ans -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
import math

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

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

Submission status: Wrong Answer

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

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


a, b, c, d = (int(i) for i in input().split())
m = lcm(c, d)
#print(m)
print((b-a+1)-(int((b)/c)-int((a-1)/c))-(int((b)/d)-int((a-1)/d))+(int((b)/(m))-int((a-1)/(m))))
#print("b-a", (b-a))
#print(int((b)/c)-int((a-1)/c))
#print((int((b)/d)-int((a-1)/d)))
#print((int((b-1)/m)-int((a-1)/m)))

Submission status: Wrong Answer

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

num_div_C = math.floor(B / C) - math.floor(A / C)
if B % C == 0:
    num_div_C += 1
num_div_D = math.floor(B / D) - math.floor(A / D)
if B % D == 0:
    num_div_D += 1
lcm = C * D // fractions.gcd(C, D)
num_div_CD = math.floor(B / lcm) - math.floor(A / lcm)
if B % lcm == 0:
    num_div_CD += 1


print(B - A + 1 - (num_div_C + num_div_D - num_div_CD))

Submission status: Wrong Answer

Solution code:
#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b / gcd(a,b)
a,b,c,d = map(int,input().split())
canC = int(b/c - (a-1)/c)
canD = int(b/d - (a-1)/d)
dbCD = int(b/lcm(c,d) - (a-1)/lcm(c,d))
print((b-a+1) -canC - canD + dbCD)

Submission status: Wrong Answer

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

import fractions

E=D * C // fractions.gcd(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 nC_final<nC_initial:
    nC_final=nC_initial
if nD_final<nD_initial:
    nD_final=nD_initial
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:
from fractions import gcd
A,B,C,D = map(int, input().split())

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

Submission status: Wrong Answer

Solution code:

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

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

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

s = -1
c = C * (A // C + 1)
if c <= B:
    s += (B - c) // C + 1
        
d = D * (A // D + 1)
if d <= B:
    s += (B - d) // D + 1
    
cd_lcm = lcm(C, D)
cdl = cd_lcm * (A // cd_lcm + 1)
if cdl <= B:
    s -= (B - cdl) // cd_lcm + 1

print(B - A - s)

Submission status: Wrong Answer

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

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

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

A,B,C,D = list(map(int, input().split()))
print(f(B, C, D)-f(A-1, C, D))

Submission status: Wrong Answer

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

def euc(a,b):
    x = a*b
    if(a<b):
        t = b
        b = a
        a = t
    
    r = a%b
    while(r!=0):
        a = b
        b = r
        r = a%b
    
    return int(x/b)

w = euc(C,D)
    
nc = int(B/C)-int((A-1)/C)
nd = int(B/D)-int((A-1)/D)
ncd = int(B/w)-int((A-1)/w)

n = nc + nd - ncd

print(B-A +1 -n)

Submission status: Wrong Answer

Solution code:
import fractions
a = list(map(int, input().split()))
if a[0]==a[1]:
    if a[0]%a[2]!=0 or a[0]%a[3]!=0:
        print(0)
    else:
        print(1)
else:
    n = a[1]-a[0]+1
    wac = int(a[1]/a[2])-int(a[0]/a[2])

    if a[0]%a[2]==0:
        wac+=1
    wad= int(a[1]/a[3])-int(a[0]/a[3])

    if a[0]%a[3]==0:
        wad+=1
    lcm = a[2]*a[3]//fractions.gcd(a[2], a[3])
    cd = int(a[1]/lcm)-int(a[0]/lcm)

    if a[0]%lcm==0:
        cd +=1

    print(n-wac-wad+cd)

Submission status: Wrong Answer

Solution code:
#最大公約数
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
#最小公倍数
def lcm(x,y):
    return (x*y//gcd(x,y))


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

if C==D:
    print(B+1-A-(B//C-A//C)-1)
elif A==C or A==D or B==C or B==D:
    print(B+1-A-(B//C-A//C)-2)
else:
    c = (B+1)//C-A//C
    d = (B+1)//D-A//D
    e = (B+1)//CDlcm-A//CDlcm
    print((B-A+1)-c-d+e)
print(CDlcm)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- Coding: utf-8 -*-

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

for i in range(A,B):
    if i%C==0:
        continue
    if i%D==0:
        continue
    cnt+=1 

print(cnt)

Submission status: Wrong Answer

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

# 1からNでs,tで割れないもの
def nonDivided(n,s,t):
    if not n > 0:
        return 0
    else:
        return n-int(n/s)-int(n/t)+int(n*gcd(s,t)/(s*t))

if __name__=='__main__':
    a,b,c,d = map(int,input().split())
    print(nonDivided(b,c,d)-nonDivided(a-1,c,d))

Submission status: Wrong Answer

Solution code:
#data=list(input().split())
a,b,c,d=map(int,input().split())
def gcd(x , y):
    if y == 0:
        return x 
    else:
        return gcd(y, x%y)

def gys(a,b):
    remainder = gcd(a,b)
    return int(a*b/remainder)

lcmm=gys(c,d)
def ans(n,k):
    return int(n/k)
def x(s):
    return ans(s,c)+ans(s,d)-ans(s,lcmm)
#print(x(b),x(a))

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

Submission status: Wrong Answer

Solution code:
#c.py
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def lcm(a, b):
    return a * b / gcd(a,b)
a,b,c,d = map(int,input().split())
canC = b/c - (a-1)/c
canD = b/d - (a-1)/d
dbCD = b/lcm(c,d) - (a-1)/lcm(c,d)
print(int((b-a+1) -canC - canD + dbCD))

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)

cd = lcm(c, d)

# cの倍数とdの倍数の個数を数える
ca = (a // c)
# print(ca)
cb = (b // c)
# print(cb)
tmp_c = cb - ca

da = (a // d)
# print(da)
db = (b // d)
# print(db)
tmp_d = db - da

cda = (a // cd)
# print(cda)
cdb = (b // cd)
# print(cdb)
tmp_cd = cdb - cda
ans = b - a - (tmp_c + tmp_d - tmp_cd) + 1

print(ans)

Submission status: Wrong Answer

Solution code:
#最大公約数
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a
#最小公倍数
def lcm(x,y):
    return (x*y//gcd(x,y))


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

if C==D:
    print(B+1-A-(B//C-A//C)-1)
if A==C or A==D or B==C or B==D:
    print(B+1-A-(B//C-A//C)-2)
else:
    c = (B+1)//C-A//C
    d = (B+1)//D-A//D
    e = (B+1)//CDlcm-A//CDlcm
    print((B-A+1)-c-d+e)
print(CDlcm)

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
ans=b-a+1
#for i in range(a,b+1):
#  if not(i%c==0 or i%d==0):
#    ans+=1
minac=c*(-(-a//c))
minad=d*(-(-a//d))
maxbc=c*(b//c)
maxbd=d*(b//d)
cn=(maxbc-minac)//c+1
dn=(maxbd-minad)//d+1
cdn=(max(maxbc,maxbd)-min(minac,minad))//(c*d)+1
ans-=(cn+dn-cdn)
print(ans)