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())
i1 = d
i2 = c
r = i1 % i2
while r != 0:
    i1 = i2
    i2 = r
    r = i1 % i2
lcm = c * d / i2
v1 = b // d - (a-1) // d
v2 = b // c - (a-1) // c
v3 = b // lcm - (a-1) // lcm
print(int(b-a+1-v1-v2+v3))

Submission status: Wrong Answer

Solution code:
import math
import fractions

def main():

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

    CD = C * D / fractions.gcd(C,D)
    #print("CD = ", CD)

    count_C = B//C - (A-1)//C
    #print("count_C = ", count_C)

    count_D = B//D - (A-1)//D
    #print("count_D = ", count_D)

    count_CD = B//int(CD) - (A-1)// int(CD)
    #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 fractions
a, b, c, d = map(int, input().split())
"""
if a==b:
  if a%c==0 or a%d==0:
    print(0)
  else:
    print(1)
"""
if c==1 or d==1:
  print(0)
else:
  cd = int(c*d/fractions.gcd(c, d))
  waru_c = int(b/c)-int((a-1)/c)
  waru_d = int(b/d)-int((a-1)/d)
  waru_cd = int(b/cd)-int((a-1)/cd)
  print((b-a+1)-(waru_c+waru_d-waru_cd))

Submission status: Wrong Answer

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

s=c*d//fractions.gcd(c, d)
bk=0
ak=0
ans=0
bc=b//c
ac=a//c    
bd=b//d
ad=a//d
bsa=b//s
asa=a//s
bk=b-bc-bd+bsa
ak=a-ac-ad+asa
ans=bk-ak
if a%c!=0 or a%d!=0 or a%s!=0 or b%c!=0 or b%d!=0 or b%s!=0:
    print(ans+1)
else:
    print(ans)

Submission status: Wrong Answer

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

from fractions import gcd


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


def mm(a, b, n):
    if a + n > b:
        return 0
    z = a + n - a % n
    return (B - z) // n + 1


E = lcm(C, D)
tc = mm(A, B, C)
td = mm(A, B, D)
te = mm(A, B, E)

print(B - A - (tc + td - te - 1))

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())
if c == 1 or d == 1:
    print(0)
    exit()
sa = b-a+1
a1 = int((sa + a%c)/c)
a2 = int((sa + a%d)/d)
a3 = int((sa + a%(lcm(c, d)))/(lcm(c, d)))
print(sa-a1-a2+a3)
#print(a1)
#print(a2)
#print(a3)
#print(lcm(c, d))
#31
# 12 18 24 30 36
# 16 24 32 40
#3+2-1 = 4
#9-4+1 - 4

Submission status: Wrong Answer

Solution code:
A,B,C,D =list(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:
def gcd(a,b):
  if a < b:
    a, b = b, a
  while a % b != 0:
    a, b = b, a % b
  return b

def getAns(a, b, c):
  if a % c == 0:
    start = a
  else:
    start = a + c - (a % c)
    if start > b:
      return 0
    
  if b % c == 0:
    end = b
  else:
    end = b - c + (b % c)
    if end < a:
      return 0
    
  num_c = max((end - start) // c + 1, 0)
  return num_c

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

# cについて
num_c =getAns(a,b,c)
#print(num_c)

# dについて
num_d =getAns(a,b,d)
#print(num_d)

# cとdの公倍数について
cd = c * d // gcd(c,d)
num_cd = getAns(a,b,cd)
#print(num_cd)

print(b - a - 1 - (num_c + num_d - num_cd))

Submission status: Wrong Answer

Solution code:
import numpy as np

def lcm(x, y):

   #  获取最大的数
   if x > y:
       greater = x
   else:
       greater = y

   while(True):
       if((greater % x == 0) and (greater % y == 0)):
           lcm = greater
           break
       greater += 1

   return lcm

a = input().split(" ")


A = int(a[0])
B = int(a[1])
C = int(a[2])
D = int(a[3])

min = min(C,D)
max = max(C,D)

gcd = lcm(min,max)

c_num = 0
if A%min == 0:
     c_num = int(B/min) - int(A/min) + 1
else:
    c_num = int(B/min) - int(A/min)

d_num = 0
if A%max == 0:
     d_num = int(B/max) - int(A/max) + 1
else:
    d_num = int(B/max) - int(A/max)


gcd_num = 0
if A%gcd == 0:
     gcd_num = int(B/gcd) - int(A/gcd) + 1
else:
    gcd_num = int(B/gcd) - int(A/gcd)


print(B-A+1-c_num-d_num+gcd_num)

Submission status: Wrong Answer

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

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

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

Anum = A-1 - (int((A-1)/C) + int((A-1)/D) - int((A-1)/E))
Bnum = B - (int(B/C) + int(B/D) - int(B/E))

print(Bnum - Anum)

Submission status: Wrong Answer

Solution code:
import math
def gcd(a,b): 
  if a==0: 
    return b 
  return gcd(b%a,a)
def lcm(a,b):
  return a*b/gcd(a,b)
a,b,c,d=map(int,input().split())
div_c=(((b-a)+1)/c)
div_d=(((b-a)+1)/d)
tot_div=(((b-a)+1)/lcm(c,d))
    #print(div_c)
    #print(div_d)
    #print(tot_div)
print(((b-a)+1)-round(div_c+div_d-tot_div))

Submission status: Wrong Answer

Solution code:
import math
import fractions

def main():

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

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

    count_C = B//C - (A-1)//C
    print("count_C = ", count_C)

    count_D = B//D - (A-1)//D
    print("count_D = ", count_D)

    count_CD = B//int(CD) - (A-1)// int(CD)
    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:
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-1)

Submission status: Wrong Answer

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



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

#lst = [i for i in range(a, b + 1)]

n = abs((b // c) - ((a - 1) // c))
m = abs((b // d) - ((a - 1) // d))
cd = c * d
f =  c * d / gcd(c, d)
if a <= f and f <= b:
    cd = f
l = abs((b // cd) - ((a - 1) // cd))


nml = n + m - l

#print(n, m, l, nml)

print(int((b - a + 1) - nml))

Submission status: Wrong Answer

Solution code:
import math
import fractions
a,b,c,d=list(map(int,input().split()))
s=math.floor(b/c)-math.ceil(a/c)+1
e=math.floor(b/d)-math.ceil(a/d)+1
count=b-a-s-e+1
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.ceil(a/com)+1
print(count+tmp)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

if C == 1 or D == 1 :
    print(0)
elif min(C,D) > B :
    print(A - B + 1)
elif max(C,D) > B :
    Z = min(C,D)
    ans = B - A + 1 - countX(Z)
    print(ans)
else :
    ans = B - A + 1

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

        return maxX - minX + 1

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

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Wrong Answer

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

if B<C:
    if B<D:
        print(B-A+1)
    else:
        ist=(A-A%D)/D
        ien=(B-B%D)/D
        print(B-A+1-ien+ist-1)
elif B<D:
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    print(B-A+1-ien+ist-1)
else:
    ist,ien,jst,jen,kst,ken=1,1,1,1,1,0
    ist=(A-A%C)/C
    ien=(B-B%C)/C
    jst=(A-A%D)/D
    jen=(B-B%D)/D
    ist=(A-A%(C*D))/(C*D)
    ien=(B-B%(C*D))/(C*D)
    print(B-A+1-ien+ist-1-jen+jst-1+ken-kst+1)

Submission status: Wrong Answer

Solution code:
import math


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


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

print(A)

Submission status: Wrong Answer

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

g = gcd(c,d)
n = c / g
m = d / g
temp = n*m*g

cc = -int(a/c) + int(b/c)
dd = -int(a/d) + int(b/d)
cd = -int(a/temp) + int(b / temp)

if c == 1 or d == 1:
    print(0)
else:
    print(ans - cc - dd + cd)

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 = int(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:
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 = x
        else:
            return z

# import math
a, b, c, d = map(int, input().split())
b_c = int(b/c)
b_d = int(b/d)
cd = c * d // gcd(c,d)
b_cd = b // cd
bn = b_c + b_d - b_cd
# print("bn:",bn)
a -= 1
a_c = int(a/c)
a_d = int(a/d)
a_cd = a // cd
an = a_c + a_d - a_cd
# print("an:",an)

num = b - a - (bn - an)
print(num)

Submission status: Wrong Answer

Solution code:
import fractions

A, B, C, D = map(int, input().split())
A -= 1
tmp = fractions.gcd(C, D)
lcd = int((C * D) / tmp)
acnt1 = int(A / C)
acnt2 = int(A / D)
acnt3 = int(B / C)
acnt4 = int(B / D)
acnt5 = int(A / lcd)
acnt6 = int(B / lcd)
ans = B - A
atmp = acnt3 + acnt4 - acnt5 - acnt6 - acnt1 - acnt2
ans -= atmp
print(ans)

Submission status: Wrong Answer

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

  
a,b,c,d = map(int,input().split())
g = c*d // gcd(c,d)
num = g - (g//c) - (g//d) + 1
n_a = (a//g) + (a%g != 0)
n_b = (b//g) + (b%g != 0)


count = 0

if n_b == n_a:
  mi = (a-1)-((n_a-1)*g)
  mib = b - (n_b -1)*num
  count += (mib - (mib//c) - (mib//d)) - (mi - (mi//c) - (mi//d))
elif n_b - n_a == 1 :
  mi = (a-1)-((n_a-1)*g)
  count += num - (mi - (mi//c) - (mi//d))
  nb = b-(n_b-1)*g
  count += nb - (nb//c) - (nb//d)
else:
  count = 0
  #count += num * (n_b - n_a - 1)
  mib = b - (n_b-1)*num
  mi = a-1
  count += (b - (b//c) - (b//d)) - (mi - (mi//c) - (mi//d)) + (n_b - n_a)
  
  
print(count)

Submission status: Wrong Answer

Solution code:
A,B,C,D = [int(i) for i in input().split()] 
d = [i + A for i in range(B-A+1) ]
d2 = list(filter(lambda x: (x % C != 0) and (x % D != 0), d) )
#d3  = list(filter(lambda x: x % D != 0, d) )
len(d2)

Submission status: Wrong Answer

Solution code:
import fractions
A,B,C,D=map(int,input().split())
X=0
L=0
M=0
N=0
E=C*D//fractions.gcd(C,D)
if A%C==0 or B%C==0:
    L=(B-A)//C+1
else:
    L=(B-A)//C

if A%D==0 or B%D==0:
    M=(B-A)//D+1
else:
    M=(B-A)//D
if B-A>=E:
    if A%E==0 or B%E==0:
        N=(B-A)//E+1
    else:
        N=(B-A)//E
else:
    if B<E :
        N=0
    else :
        if A%E==0 or B%E==0:
            N=(B-A)//E+2
        else:
            N=(B-A)//E+1    
X=B-A+1-L-M+N
print(X)

Submission status: Wrong Answer

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

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

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

Anum = A-1 - (int((A-1)/C) + int((A-1)/D) - int((A-1)/E))
Bnum = B - (int(B/C) + int(B/D) - int(B/E))

print(Bnum - Anum)

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())
CD=lcm(C, D)

def xc(x,C=C,D=D,CD=CD):
    return(x//C+x//D-x//(CD))

print(B-A+1-xc(B+1)+xc(A))

Submission status: Wrong Answer

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

s = input().split(" ");
a = int(s[0]);
b = int(s[1]);
c = int(s[2]);
d = int(s[3]);
if a % c == 0 :
	min_c = int(a/c) - 1;
else :
	min_c = int(a/c);
if a % d == 0 :
	min_d = int(a/d) - 1;
else :
	min_d = int(a/d);
if a % lcm(c, d) == 0 :
	min_cd = int(a/lcm(c, d)) - 1;
else :
	min_cd = int(a/lcm(c, d));
num_c = int(b/c) - min_c;
num_d = int(b/d) - min_d; 
num_cd = int(b/lcm(c, d)) - min_cd;
print(b - a + 1 -(num_c + num_d - num_cd))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import fractions
A,B,C,D=map(int,input().split())
if min(C,D)>B:
    print(0)
    exit()
c=math.floor(B/C)
cc=math.ceil(A/C)

d=math.floor(B/D)
dd=math.ceil(A/D)
CD=(C*D)//fractions.gcd(C,D)
cd=math.floor(B/(CD))
cdcd=math.ceil(A/(CD))

print((B-A+1)-((c-cc+1)+(d-dd+1)-(cd-cdcd+1)))

Submission status: Wrong Answer

Solution code:
import fractions

ABCD = list(map(int, input().split()))

A = ABCD[0]
B = ABCD[1]
C = ABCD[2]
D = ABCD[3]


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

AB = B-A
count = 0

firstC = int(A/C)
if A%C == 0:
    firstC -= 1
firstD = int(A/D)

if A%D == 0:
    firstD -= 1

firstCD = int(A/lcm(C,D))
if A%lcm(C,D) ==0:
    firstCD -= 1

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

thereC = endC - firstC
thereD = endD - firstD
thereCD = endCD - firstCD

NoP = thereC+thereD - thereCD
#
# print(thereC)
# print(thereD)
# print(thereCD)
# print(NoP)

print(B-A+1-NoP)

Submission status: Wrong Answer

Solution code:
import math

line = input().split()

a = int(line[0])
b = int(line[1])
c = int(line[2])
d = int(line[3])

count = 0

ran = b-a
c_c = ran//c
d_c = ran//d
cd_c = ran//(c*d)
rang = c_c+d_c-cd_c
result_c = ran - rang
  

print(result_c)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import fractions
a, b, c, d = map(int, input().split())

# cで割り切れる個数を求める
c_div = abs((b // c) - (a // c))
#print(c_div)

# dで割り切れる個数を求める
d_div = abs((b // d) - (a // d))
#print(d_div)

# cとd両方で割り切れる数を求める
cd = (c * d) // fractions.gcd(c, d)
cd_div = abs((b // cd) - (a // cd))
#print(cd_div)

div =  c_div  + d_div - cd_div

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

Submission status: Wrong Answer

Solution code:
import fractions as m
def lcm(x, y):
  return (x * y) / m.gcd(x, y)
  
x = input()
x = str(x).split(" ")
f = 0
 
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])
 
n = b-a+1
 
if c-a%c < n%c :
  f+=1
 
if d-a%d < n%d :
  f+=1
 
if c*d-a%(c*d) < n%(lcm(c, d)) :
  f-=1
  
print( n - int(n/d) - int(n/c) + int(n/(lcm(c, d)) - f))

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int,input().split())
ll = B - A + 1
C_min = 0
D_min = 0
CD_min = 0
for i in range(A,B+1):
  if i % C == 0:
    C_min = i
  if i % D == 0:
    D_min = i
  if i % C == 0 and i % D == 0:
    CD_min = i
  if C_min > 0 and D_min > 0 and CD_min > 0:
    break
  if ll > C and D_min > 0 and CD_min > 0:
    break
  if ll > D and C_min > 0 and CD_min > 0:
    break
  if ll > C*D and C_min > 0 and D_min > 0:
    break
C_cou = 0
D_cou = 0
CD_cou = 0
if C_min > 0:
	C_cou = (B - C_min) // C + 1
if D_min > 0:
	D_cou = (B - D_min) // D + 1
if CD_min > 0:
	CD_cou = (B - CD_min) // (C*D) + 1
ans = B - A - C_cou - D_cou + CD_cou + 1
print(ans)

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

if C == 1 or D == 1 :
    print(0)
elif min(C,D) > B :
    print(A - B + 1)
else :
    ans = B - A + 1

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

        return maxX - minX + 1

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

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Wrong Answer

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

A =A-1
CD = int(C * D / gcd(C, D))
num_A_C = int(A / C)
num_A_D = int(A / D)
num_A_CD = int(A / CD)
num_B_C = int(B / C)
num_B_D = int(B / D)
num_B_CD = int(B / CD)

num_C =num_B_C - num_A_C
num_D =num_B_D - num_A_D
num_CD =num_B_CD - num_A_CD

ans = B - A -num_C - num_D + num_CD
print(ans)

Submission status: Wrong Answer

Solution code:
import math
from fractions import gcd

def number_calc(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    res = max(right-left+1,0)
    return res

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

ans = B-A+1
ans -=number_calc(A,B,C)
ans -=number_calc(A,B,D)
lcm = (C*D)//gcd(C,D)
ans +=number_calc(A,B,lcm)

print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
e = int(c*d/fractions.gcd(c, d))
if a%c != 0:
	fc = (int(a/c)+1)*c
else:
	fc = (int(a/c))*c
if b%c != 0:
	tc = (int(b/c))*c
else:
	tc = (int(b/c))*c
sc = int((tc - fc)/c)+1
if fc > tc:
  sc = 0

if a%d != 0:
	fd = (int(a/d)+1)*d
else:
	fd = (int(a/d))*d
if b%d != 0:
	td = (int(b/d))*d
else:
	td = (int(b/d))*d
sd = int((td - fd)/d)+1
if sd > td:
  sd = 0

if a%e != 0:
	fe = (int(a/e)+1)*e
else:
	fe = (int(a/e))*e
if b%e != 0:
	te = (int(b/e))*e
else:
	te = (int(b/e))*e
se = int((te - fe)/e)+1
if fe > te:
  se = 0

ss = (b-a+1)-(sc+sd-se)
print(ss)

Submission status: Wrong Answer

Solution code:
import math
import fractions

A, B, C, D = map(int, input().split())
N = B - A + 1  #整数列の長さ

if C == D:
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    print(N-tmp)
elif fractions.gcd(C,D) & 1:
    tmp = 0   #最後にNから引く
    mod = A % C
    tmp += math.ceil((N-mod)/C)
    mod = A % D
    tmp += math.ceil((N-mod)/D)
    mod = A % (D*C)
    tmp -= math.ceil((N-mod)/(D*C))
    print(N-tmp)
else:
    tmp = 0   #最後にNから引く
    mod = A % min(C, D)
    tmp += math.ceil((N-mod)/min(C, D))
    print(N-tmp)

Submission status: Wrong Answer

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

A_div_byCorD = (A-1)//C + (A-1)//D - (A-1)//(C*D)
B_div_byCorD = B//C + B//D - B//(C*D)
#print(A_div_byCorD)
#print(B_div_byCorD)
canbedivided = B_div_byCorD - A_div_byCorD

print(B-A+1 - canbedivided)

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())
CD = lcm(C,D)
C_num = B//C-A//C+(1 if A%C==0 else 0)
D_num = B//D-A//D+(1 if A%D==0 else 0)
CD_num = B//CD-A//CD
print(B-A+1-C_num-D_num+CD_num)

Submission status: Wrong Answer

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

from fractions import gcd
from math import ceil,floor

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


Cans = floor(B/C) - ceil(A/C) + 1
Dans = floor(B/D) - ceil(A/D) + 1

CD = C * D // gcd(C,D)
CDans = floor(B/CD) - ceil(A/CD) + 1

ans = (B-A+1) - (Cans + Dans - CDans)

print(ans)

Submission status: Wrong Answer

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

l = raw_input().split()

a = int(l[0])
b = int(l[1])
c = int(l[2])
d = int(l[3])
if(c>d):
    c = int(l[3])
    d = int(l[2])

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

div = []

div.append((a-1)/c)
div.append((a-1)/d)

div.append(b/c)
div.append(b/d)

div.append(a/lcm)
div.append(b/lcm)

ans =  (div[2]-div[0])+(div[3]-div[1])-(div[5]-div[4])
ans = (b-a+1) - ans

print ans

Submission status: Wrong Answer

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

if C==D:
    duplicate=C
elif C>D and C%D == 0:
    duplicate = C
elif D>C and D%C == 0:
    duplicate = D
else:
    duplicate = C*D

cCnt = (B - A) // C
dCnt = (B - A) // D
duplicateCnt = (B - A) // duplicate

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

Submission status: Wrong Answer

Solution code:
import fractions

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

if a % c == 0:
    c_start = int(a/c)
else:
    c_start = int(a/c)+1

if a % d == 0:
    d_start = int(a/d)
else:
    d_start = int(a/d)+1

if a % lcm == 0:
        lcm_start = int(a/lcm)
else:
        lcm_start = int(a/lcm)+1

c_end = int(b/c)
d_end = int(b/d)
lcm_end = int(b/lcm)

c_num = c_end - c_start + 1
d_num = d_end - d_start + 1
lcm_num=lcm_end - lcm_start + 1

print(b - a + 1 - c_num - d_num + lcm_num)

Submission status: Wrong Answer

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

k = B-A+1 #A以上B以下の整数の個数

#A~Bの中に何個Cの倍数があるか
p=0
while(p*C<A):
    p+=1
q=0
while(q*C<B):
    q+=1
#Cの倍数はq-p個

#A~Bの中に何個Dの倍数があるか

r=0
while(r*D<A):
    r+=1
s=0
while(s*D<B):
    s+=1
#Dの倍数はs-t個
    
#A~Bの中に何個C*Dの倍数があるか

t=0
while(t*C*D<A):
    t+=1
u=0
while(u*C*D<B):
    u+=1
#C*Dの倍数はu-t個
    
    
print(k-(q-p)-(s-r)+(u-t))

Submission status: Wrong Answer

Solution code:

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

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


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


sais = lcm(C, D)

buff_a = A - 1


sais_mx = B // sais
sais_mm = buff_a // sais
sais_count = sais_mx - sais_mm
if sais_mx > 0:
    sais_count = sais_mx + sais_mm
else:
    sais_count = 0

# print('sais_mx ' + str(sais_mx))
# print('sais_count ' + str(sais_count))

c_mx = B // C
c_mm = buff_a // C
c_count = c_mx - c_mm

d_mx = B // D
d_mm = buff_a // D
d_count = d_mx - d_mm

# print("c d")
# print(c_count, d_count)
zentai = c_count + d_count

# zentai = zentai - (sais_count*2)
zentai = zentai - (sais_count)

b_a = B - A
ans = b_a - zentai
# print(zentai)
print(ans+1)

Submission status: Wrong Answer

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

ac = a//c
bc = b//c
ad = a//d
bd = b//d

o = max(c, d)
p = min(c, d)

gcd_ = gcd(o,p)
lcm = int(c*d/gcd_)

acd = a//lcm
bcd = b//lcm

print(int(b-a+1-(bc-ac+bd-ad-(bcd-acd))))

Submission status: Wrong Answer

Solution code:
import math
import fractions
A, B, C, D = map(int, input().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a = math.ceil((B / C) - (A / C))
b = math.ceil((B / D) - (A / D))
c = lcm(C, D)
while c < A:
    c += c
tmp = 0
while c <= B:
    c += c
    tmp += 1
print(B - A + 1 - (a + b - tmp))

Submission status: Wrong Answer

Solution code:
#C
from math import ceil, floor
from fractions import gcd
A,B,C,D = map(int, input().split())
X = int(C * D / gcd(C, D))

def retLR(A, B, num):
    #return A <= l*num < r*num <= B, length
    l = ceil(A/num)
    r = floor(B/num)
    if r*num < A and B < l*num :
        length = 0
    elif (r*num < A and l*num <= B) or (A <= r*num and B < l*num) : 
        length = 1
    else:
        length = r - l + 1
    return length

a1 = retLR(A,B,C)
a2 = retLR(A,B,D)
a3 = retLR(A,B,X)

if C == D:
    subst = a1
else:
    subst = a1 + a2 - a3
if A == B:
    if A == C or A == D: ans = 0
    else: ans = 1
else:
    ans = (B - A + 1) - subst
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import fractions

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

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

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

        return maxX - minX + 1

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

    ans -= countX(C)
    ans -= countX(D)
    ans += countX(Z)

    print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
a, b, c, d = map(int, input().split())
if a==b:
  if a%c==0 or a%d==0:
    print(0)
  else:
    print(1)
elif c==1 or d==1:
  print(0)
else:
  cd = int(c*d/fractions.gcd(c, d))
  waru_c = int(b/c)-int((a-1)/c)
  waru_d = int(b/d)-int((a-1)/d)
  waru_cd = int(b/cd)-int((a-1)/cd)
  print((b-a+1)-(waru_c+waru_d-waru_cd))

Submission status: Wrong Answer

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

C_ = int(B/C) - int(A/C)
if A % C == 0:                                                                                                                                                                                              
    C_ += 1                                                                                                                                                                                                 
D_ = int(B/D) - int(A/D)
if A % D == 0:                                                                                                                                                                                              
    D_ += 1                                                                                                                                                                                                 

E = int(C * D // int(fractions.gcd(C, D)))
E_ = int(B/E) - int(A/E)
if A % E == 0:                                                                                                                                                                                              
    E_ += 1                                                                                                                                                                                                 

ans = B - A + 1 - C_ - D_ + E_
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())
sa = b-a
a1 = int((sa + a%c)/c)
a2 = int((sa + a%d)/d)
a3 = int((sa + a%(lcm(c, d)))/(lcm(c, d)))
print(sa-a1-a2+a3+1)
#print(a1)
#print(a2)
#print(a3)
#print(lcm(c, d))
#31
# 12 18 24 30 36
# 16 24 32 40
#3+2-1 = 4
#9-4+1 - 4

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())
c1 = (b // c) - (a // c)
if a % c == 0:
    c1 += 1
d1 = (b // d) - (a // d)
if a % d == 0:
    d1 += 1
lam1 = lcm(c, d)
cd = (b // (lam1)) - (a // (lam1))
print((b - a + 1) - ((c1 + d1) - cd))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import fractions
import math

A,B,C,D = map(int,input().split())
lcm = C*D/fractions.gcd(C,D)
def c_in_a2b(c):
    if c > B:
        return 0
    else:
        return (math.floor(B/c) - math.ceil(A/c) + 1)
print(int((B-A+1)- c_in_a2b(C)-c_in_a2b(D)+c_in_a2b(lcm)))

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(x, y):
    return int((x * y) / gcd(x, y))
a,b,c,d = map(int,input().split())
count = 0
if c == 1 or d == 1:
    print(0)
else:
    lcm = lcm(c,d)
    ans1 = (b // c - a-1 // c + b // d - a-1 // d - b // lcm + a-1// lcm)
    print(b - a + 1 - ans1)

Submission status: Wrong Answer

Solution code:
A,B,C,D=map(int,input().split())
e=A//C
f=B//C
g=A//D
h=B//D
L1=[i*C for i in range(e,f)]
L2=[ii*D for ii in range(g,h)]
L3=L1+L2
print(B-A-len(set(L3)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A, B, C, D = map(int, input().split())
a = [A//C, A//D, A//(C*D), B//C, B//D, B//(C*D)]
ans = (B-A + 1) - (a[3] - a[0]) - (a[4] - a[1]) + (a[5] - a[2] )
if (A%C == 0) or (A%D == 0):
  ans -= 1

  
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

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

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

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

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

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int, input().split())
count = 0
num=b-a+1
import fractions
lcm= int(c*d / fractions.gcd(c,d))
div_ac=a//c
div_ad=a//d
div_acd=a//lcm

div_bc=b//c
div_bd=b//d
div_bcd=b//lcm

print(num-((div_bc+div_bd-div_bcd)-(div_ac+div_ad-div_acd)))

Submission status: Wrong Answer

Solution code:
a,b,c,d=map(int,input().split())
import math
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
cb=math.floor(b/c)
ca=math.floor(a/c)
cc=cb-ca
db=math.floor(b/d)
da=math.floor(a/d)
dd=db-da
lcm=c*d/gcd(c,d)
nb=math.floor(b/lcm)
na=math.floor(a/lcm)
nn=nb-na
print(b+1-a-(cc+dd-nn))

Submission status: Wrong Answer

Solution code:

a,b,c,d=map(int,input().split())
cc=int((b-a)/c)
dd=int((b-a)/d)
cd=0

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

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

    if x != 0:
        f.append(x)
    k.sort()
    k[1] = x
cd=int((b-a)/(c*d/min(f)))
print(b-a-cc-dd+cd)

Submission status: Wrong Answer

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

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

def nonDivided(n,s,t):
    if not n > 0:
        return 0
    else:
        lcm = int(s*t/gcd(s,t))
        return n-int(n/s)-int(n/t)+int(n/lcm)

if __name__=='__main__':
    A,B,C,D = map(int,input().split())
    print(nonDivided(B,C,D)-nonDivided(A-1,C,D))