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: Runtime Error

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

count_c = b // c - (a-1) // c
count_d = b // d - (a-1) // d
lcm_cd = c * d / math.gcd(c, d)
count_cd = b // lcm_cd - (a-1) // lcm_cd

print(b - a - int(count_c+count_d-count_cd) + 1)

Submission status: Runtime Error

Solution code:
def uc(d, c):
  if c ==0:
    return d
  else:
    return uc(c, d%c)


A, B, C, D = map(int,input().split())
maxi = uc(D, C)
mini = C*D/maxi

res = [0,0,0]
for i in range(A, B+1):
  if i%C == 0: res[0]+=1
  if i%D == 0: res[1]+=1
  if i%mini == 0: res[2]+=1

ans = B-A+1 -(res[0]+res[1]-res[2])
pribt(ans)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
n = b - a + 1
bc = int(b / c)
ac = int((a - 1) / c)
bd = int(b / d)
ad = int((a - 1) / d)
bac = bc - ac
bad = bd - ad

cd = c * d / math.gcd(c, d)
bcd = int(b / cd)
acd = int((a - 1) / cd)
abcd = bcd - acd
print(n - bac - bad + abcd)

Submission status: Runtime Error

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

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

div_A_C = (A-1)//C
div_A_D = (A-1)//D

div_B_C = B//C
div_B_D = B//D

CD = lcm(C, D)

div_A_CD = (A-1)//CD
div_B_CD = B // CD
C_or_D = (div_B_C+div_B_D-div_B_CD)-(div_A_C+div_A_D-div_A_CD) 
print(B-A+1-C_or_D)

Submission status: Runtime Error

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

n_u=b-a+1

#引数にx,y,zを与えるとx~yの範囲のzの倍数の数を返す関数を作る
def f(x,y,z):
    ans=0
    if x+z<y:
        l=x+z
    else:
        l=y
    for i in range(x,l+1):
        if i%z==0:
            ans=(y-i)//z+1
            break
    return ans
#2数を引数にすると最小公倍数を返す関数を作る
def lcm(x,y):
    return x*y//math.gcd(x,y)

n_c=f(a,b,c)
n_d=f(a,b,d)
n_lcm=f(a,b,lcm(c,d))

print(n_u-n_c-n_d+n_lcm)

Submission status: Runtime Error

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

import math
def lcm(x,y):
    return x*y//math.gcd(x,y)
lcm=lcm(c,d)
for i in range(a,b+1):
    if i%lcm==0:
        c=i
        break
print(b-a-(b-c)//lcm)

Submission status: Runtime Error

Solution code:
import math

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


def main():
    a,b,c,d = map(int,input().split())
    c_mul_count = b//c - (a-1)//c
    d_mul_count = b//d - (a-1)//d
    cd_lcm = lcm(c, d)
    lcm_mul_count = b//cd_lcm - (a-1)//cd_lcm
    s = b-a+1
    print(s-c_mul_count-d_mul_count+lcm_mul_count)



if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

import math

g = math.gcd(C, D)
E = C*D//g
num = (B//C-(A-1)//C) + (B//D-(A-1)//D) - (B//E-(A-1)//E)
print(B-A+1-num)

Submission status: Runtime Error

Solution code:
A,B,C,D = map(int,input().split())
def gcd(x,y):
  if x<y:
    l = y
    k = x
    x = y
    y = k
  z = x%y
  while z != 0:
    x = y
    y = z
    z = x%y
  return (k//y)*(l//y)*y

if A%C ==0:
  i = (A//C)-1
else:
  i = A//C

j = B//C

if A%D ==0:
  k = (A//D)-1
else:
  k = A//D

l = B//D

if A%(gcd(C,D)) ==0:
  m = (A//(gcd(C,D)))-1
else:
  m = A//gcd(C,D)
  
n = B//gcd(C,D)

#print(i,j,k,l,m,n)
#print(B-A+1,j-i,l-k,n-m)
print((B-A+1)-(j-i)-(l-k)+(n-m))

Submission status: Runtime Error

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

S=B-A+1
if(A%C==0):
    n_C=B//C-A//C+1
else:
     n_C=B//C-A//C

if(A%D==0):
    n_D=B//D-A//D+1
else:
    n_D=B//D-A//D

if(A%lcm(C,D)==0):
    n_CD=B//lcm(C,D)-A//lcm(C,D)+1
else:
    n_CD=B//lcm(C,D)-A//lcm(C,D)
    
print(S-n_C-n_D+n_CD)

Submission status: Runtime Error

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

ans = 0

for i in range(A, B+1):
  if i % C != and i % D !=0:
    ans += 1
    
print(ans)

Submission status: Runtime Error

Solution code:
#a以上b以下の整数のうちcでもdでも割り切れないものの個数を求めてください
#1以上b以下の整数の条件を満たすものから1以上a-1以下のもので条件を満たすものを取り除くようにすればいい
import fractions
x=c*d//fractions.gcd(c,d)
a,b,c,d=map(int,input().split())
n=b-((b//c)+(b//d)-b//(x))
m=(a-1)-((a-1)//c+(a-1)//d-(a-1)//(x))
print(n-m)

Submission status: Runtime Error

Solution code:
#a以上b以下の整数のうちcでもdでも割り切れないものの個数を求めてください
#1以上b以下の整数の条件を満たすものから1以上a-1以下のもので条件を満たすものを取り除くようにすればいい
import math
x=c*d//math.gcd(c,d)
a,b,c,d=map(int,input().split())
n=b-((b//c)+(b//d)-b//(x))
m=(a-1)-((a-1)//c+(a-1)//d-(a-1)//(x))
print(n-m)

Submission status: Runtime Error

Solution code:
import math

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

A,B,C,D=map(int, input().split())
LCM=lcm(C,D)
Ac=(A-1)//C
div_C=B//C-Ac
Ad=(A-1)//D
div_D=B//D-Ad
Alcm=(A-1)//LCM
div_CD=B//LCM-Alcm
Ans=(B-A+1)-div_C-div_D+div_CD
print(Ans)

Submission status: Runtime Error

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

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

#CとDの最小公倍数
LCM=lcm(C,D)

#A未満でCで割れる個数
Ac=(A-1)//C

#範囲内でCで割れる個数
div_C=B//C-Ac

#A未満でDで割れる個数
Ad=(A-1)//D

#範囲内でDで割れる個数
div_D=B//D-Ad

#A未満でLCMで割れる個数
Alcm=(A-1)//LCM

#範囲内でLCMで割れる個数
div_CD=B//LCM-Alcm

#解答
Ans=(B-A+1)-div_C-div_D+div_CD
print(Ans)

Submission status: Runtime Error

Solution code:
import math


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

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

def get_num(x):
    ans = x - x // c - x // d + x // lcm(c, d)
    return ans


print(get_num(b) - get_num(a -1))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import math

def solve():
    A, B, C, D = map(int, input().split())
    gcd = (C * D) // math.gcd(C, D)
    ans_sub = A-1 - ((A-1) // C + (A-1) // D - (A+1) // gcd)
    ans = B - (B // C + B // D - B // gcd) - ans_sub
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Runtime Error

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

X = list(range(A, B+1))

c = A % C
d = A % D

if c == 0:
    I = list(range(A, B+1, C))
else:
    I = list(range(A+C-c, B+1, C))
if d == 0:
    J = list(range(A, B+1, D))
else:
    J = list(range(A+D-d, B+1, D))

ans_list = list(set(X) - set(I) - set(J))
print(len(ans_list))

Submission status: Runtime Error

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

X = list(range(A, B+1))

c = A % C
d = A % D

if c == 0:
    I = list(range(A, B+1, C))
else:
    I = list(range(A+C-c, B+1, C))
if d == 0:
    J = list(range(A, B+1, D))
else:
    J = list(range(A+D-d, B+1, D))

ans_list = list(set(X) - set(I) - set(J))
print(ans_list)

Submission status: Runtime Error

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

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))

Submission status: Runtime Error

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

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))

Submission status: Runtime Error

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

ac = (A-1)//C
bc = B//C
ad = (A-1)//D
bd = B//D
acd = (A-1)//CD
bcd = B//CD

print(int(B - A + 1 - ((bc - ac) + (bd - ad) - (bcd - acd))))

Submission status: Runtime Error

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

#割り切れるやつ引く
#c,dの最小公倍数はlct
lct=c*d/math.gcd(c,d)

#print("c, d, lct")
#print(c,d,lct)

k1=math.ceil(a/c)
l1=math.ceil(a/d)
m1=math.ceil(a/lct)

#print("c1, d1, lct1")
#print(c*k1,d*l1,lct*m1)

#cの倍数の数
n_c=(b-c*k1)//c+1
n_d=(b-d*l1)//d+1
n_lct=(b-m1*lct)//lct+1

#print(n_c,n_d,n_lct)
print(b-a+1-n_c-n_d+n_lct)

Submission status: Runtime Error

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

#割り切れるやつ引く
#c,dの最小公倍数はlct
lct=c*d/math.gcd(c,d)

#print("c, d, lct")
#print(c,d,lct)

k1=math.ceil(a/c)
l1=math.ceil(a/d)
m1=math.ceil(a/lct)

#print("c1, d1, lct1")
#print(c*k1,d*l1,lct*m1)

#cの倍数の数
n_c=(b-c*k1+)//c+1
n_d=(b-d*l1+)//d+1
n_lct=(b-m1*lct+)//lct+1

#print(n_c,n_d,n_lct)
print(b-a+1-n_c-n_d+n_lct)

Submission status: Runtime Error

Solution code:
from math import gcd


def find(n, k):

    if n == 0:
        return 0
    
    return n // k

def interval(l, r, k):
    return find(r, k) - find(l - 1, k)

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

print((b - a + 1) - interval(a, b, c) - interval(a, b, d) + interval(a, b, (c * d) // gcd(c, d)))

Submission status: Runtime Error

Solution code:
from fractions import gcd

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

    X = int(B/C) - int((A-1)/C)
    Y = int(B/D) - int((A-1)/D)
    
    lcm_CD = int(C*D/fractions.gcd(C,D))
    Z = int(B/lcm_CD) - int((A-1)/lcm_CD)

    ans = B - (A-1)
    ans -= X+Y-Z

    print(ans)

solve()

Submission status: Runtime Error

Solution code:
import math

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

    X = int(B/C) - int((A-1)/C)
    Y = int(B/D) - int((A-1)/D)
    
    lcm_CD = int(C*D/math.gcd(C,D))
    Z = int(B/lcm_CD) - int((A-1)/lcm_CD)

    ans = B - (A-1)
    ans -= X+Y-Z

    print(ans)

solve()

Submission status: Runtime Error

Solution code:
import math

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

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

lcm_CD = lcm(C, D)
count = (B // C - (A-1) // C) + (B // D - (A-1) // D) - (B // lcm_CD - (A-1) // lcm_CD)
    
print((B - A + 1) - count)

Submission status: Runtime Error

Solution code:
import math

a,b,c,d=map(int,input().split())
x=c*d//math.gcd(c,d)
print(b-~-a-(b//c-~-a//c)-(b//d-~-a//d)+b//x-~-a//x)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
x=c*d//math.gcd(c,d)
print(b-~-a-(b//c-~-a//c)-(b//d-~-a//d)+b//x-~-a//x)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
cdg=math.gcd(c,d)
cd=c*d/cdg
ac=int(a/c)
ad=int(a/d)
acd=int(a/cd)
bc=int(b/c)
bd=int(b/d)
bcd=int(b/cd)
n=b-a+1
cn=0
dn=0
cdn=0
if a%c==0:
    cn=bc-ac+1
else:
    cn=bc-ac
if a%d==0:
    dn=bd-ad+1
else:
    dn=bd-ad
if a%(cd)==0:
    cdn=bcd-acd+1
else:
    cdn=bcd-acd
print(n-(cn+dn-cdn))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d=map(int,input().split())
cdg=math.gcd(c,d)
cd=c*d/cdg
ac=int(a/c)
ad=int(a/d)
acd=int(a/cd)
bc=int(b/c)
bd=int(b/d)
bcd=int(b/cd)
n=b-a+1
if a%c==0:
    cn=bc-ac+1
else:
    cn=bc-ac
if a%d==0:
    dn=bd-ad+1
else:
    dn=bd-ad
if a%(cd)==0:
    cdn=bcd-acd+1
else:
    cdn=bcd-acd
print(n-(cn+dn-cdn))

Submission status: Runtime Error

Solution code:
a, b, c, d = map(int, input().split())
import math
lcm = c * d / math.gcd(c, d)
#1~a
a_count = (a-1)//c + (a-1)//d - (a-1)//lcm
b_count = b//c + b//d - b//lcm
answer = b_count - a_count
print(b - a + 1 - answer)

Submission status: Runtime Error

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

c_m = b//c - (-(-a//c)) +1
d_m = b//d  - (-(-a//d)) + 1
cd = c*d//math.gcd(c,d)
cd_m = b//(cd) - (-(-a//(cd))) + 1

print(b-a+1 -(c_m + (d_m -cd_m)*(d%c != 0)))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int, input().split())
cd = math.gcd(c, d)
 
def f(x,y,div):
  return int(max(x,y)/div) - int((min(x,y)-1) / div)
print(a-b+1- f(a,b,c) - f(a,b,d) + f(a,b,cd))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int, input().split())
cd = math.gcd(cd)
 
def f(x,y,div):
  return int(max(x,y)/div) - int((min(x,y)-1) / div)
print(a-b+1- f(a,b,c) - f(a,b,d) + f(a,b,cd))

Submission status: Runtime Error

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

def f(x,y,div):
  return int(max(x,y)/div) - int((min(x,y)-1) / div)
print(a-b+1- f(a,b,c) - f(a,b,d) + f(a,b,cd))

Submission status: Runtime Error

Solution code:
import math


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


def main():
    A, B, C, D = map(int, input().split())
    first = B // C - A // C
    first += 1 if A % C == 0 else 0
    second = B // D - A // D
    second += 1 if A % D == 0 else 0
    tmp = lcm(C, D)
    both = B // tmp - A // tmp
    both += 1 if A % tmp == 0 else 0
    print(B - A + 1 - first - second + both)
    return


main()

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math

A,B,C,D=map(int,input().split())
A-=1
print(A)
num1=A-A//C-A//D+(A//(C*D//math.gcd(C, D)))
num2=B-B//C-B//D+(B//(C*D//math.gcd(C, D)))

print(num1)
print(num2)

print(num2-num1)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
x = b-a+1
l = c//math.gcd(c, d)*d
ans = (b//c - (a-1)//c) + (b//d - (a-1)//d) - (b//l - (a-1)//l)
print(x-ans)

Submission status: Runtime Error

Solution code:
import math
def answer(x, i, j):
    lcm = (i * j) // math.gcd(i, j)
    xi = x // i
    xj = x // j
    xlcm = x // lcm
    return x - xi - xj + xlcm
a, b, c, d = map(int, input().split())
ans = answer(b, c, d) - answer(a-1, c, d)
print(ans)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
def answer(x, i, j):
    lcm = (i * j) // math.gcd(i, j)
    xi = x // i
    xj = x // j
    xlcm = x // lcm
    return x - xi - xj + xlcm
ans = answer(b, c, d) - answer(a-1, c, d)
print(ans)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
def func(x, i, j):
    lcm = (i * j) // math.gcd(i, j)
    xi = x // i
    xj = x // j
    xlcm = x // lcm
    return x - xi - xj + xlcm
print(func(b, c, d) - func(a-1, c, d))

Submission status: Runtime Error

Solution code:
import math

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

def calc(a,b,x):
    y = a-(x-a%x)
    return (b-y)//x
print((b-a+1)-(calc(a,b,c)+calc(a,b,d)-calc(a,b,e)))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
a_0=a//c
a_1=a//d
a_2=a//lcm(c,d)
n=a_0+a_1-a_2
#print(n)
b_0=b//c
b_1=b//d
b_2=b//lcm(c,d)
m=b_0+b_1-b_2
#print(m)
#b_1-b_2
print(b-a+1-(m-n))

Submission status: Runtime Error

Solution code:
import math

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


A, B, C, D = map(int, input().split())
E = lcm(C, D)
b = B - (B // C + B // D - B // E)
a = A - (A // C + A // D - A // E)
if A % C == 0 or A % D == 0:
    print(b - a)
else:
    print(b - a + 1)

Submission status: Runtime Error

Solution code:
import math

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

def main():

    A, B, C, D = map(int, input().split())
    E = lcm(C, D)
    b = B - (B // C + B // D - B // E)
    a = A - (A // C + A // D - A // E)
    if A % C == 0 or A % D == 0:
        print(b - a)
    else:
        print(b - a + 1)

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

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

total = b - (b//c + b//d - b//lcm)
total_del = a-1 -((a-1)//c + (a-1)//d - (a-1)//lcm)

print(total - total_del)

Submission status: Runtime Error

Solution code:
import math
a, b, c, d = map(int, input().split())
div_c = b//c + (-a//c) + 1
div_d = b//d + (-a//d) + 1
div_cd = b//(c*d//math.gcd(c, d)) + (-a//(c*d//math.gcd(c,d))) + 1
print(b-a+1 - div_c - div_d + div_cd)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

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

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

b_n = B//C + B//D - B//lcm(C,D)
a_n = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)
ans_n = b_n - a_n
print(int(B-A+1-ans_n))

Submission status: Runtime Error

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

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

b_n = B//C + B//D - B//lcm(C,D)
a_n = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)
ans_n = b_n - a_n
print(ans_n)
print(B-A+1-ans_n)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

E = lcm(C, D)
count_A = (A - 1) - (A - 1)//C - (A - 1)//D + (A - 1)//E
count_B = B - B//C - B//D + B//E

print(count_B - count_A)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

A,B,C,D = list(map(int,input().split()))
lcm = C*D/math.gcd(C,D)
a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
b = (B) - ((B)//C + (B)//D - (B)//lcm)
print(int(b-a))

Submission status: Runtime Error

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

 
lcm = C*D/math.gcd(C,D)
a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
b = (B) - ((B)//C + (B)//D - (B)//lcm)
print(int(b-a))

Submission status: Runtime Error

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

lcm = C*D/math.gcd(C,D)
a = (A-1) - ((A-1)//C + (A-1)//D - (A-1)//lcm)
b = (B) - ((B)//C + (B)//D - (B)//lcm)
print(int(b-a))

Submission status: Runtime Error

Solution code:
from sys import stdin
import math

a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = math.gcd(c, d)
koubai = c * d // math.gcd(c, d)
b_s = b - b//c - b//d + b//koubai
a_s = a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai
print(b_s - a_s)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = math.gcd(c, d)
koubai = (c * d // kouyaku)
b_s = (b - b//c - b//d + b//koubai)
a_s = (a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai)
print(b_s - a_s)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
kouyaku = math.gcd(c, d)
koubai = c * d // kouyaku
b_s = b - b//c - b//d + b//koubai
a_s = a-1 - (a-1)//c - (a-1)//d + (a-1)//koubai
print(b_s - a_s)

Submission status: Runtime Error

Solution code:
A,B,C,D=map(int,input().split())
c_dividable=B//C-(A-1)//C
d_dividable=B//D-(A-1)//D
def gcd(a,b):
  if a==b:
    return q
  else:
    if a%b==0:
      return b
    while a%b!=0:
      return gcd(b,a%b)
v=C*D//gcd(C,D)
cd_dividable=B//v-(A-1)//v
print(B-A+1-(c_dividable+d_dividable-cd_dividable))

Submission status: Runtime Error

Solution code:
from math import gcd

A, B, C, D = map(int, input().split())
C_div = B // C - (A - 1) // C
D_div = B // D - (A - 1) // D
CD = C * D // gcd(C, D)
CD_div = B // CD - (A - 1) // CD
print(B - A + 1 - C_div - D_div + CD_div)

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = map(int, input().split())
A = A-1
f=math.gcd(C,D)
f2=C*D//f

Aans = A - (A//C + A//D - A//f2)
Bans = B - (B//C + B//D - B//f2)
print(Bans- Aans)

Submission status: Runtime Error

Solution code:
import math

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

X = (C * D) // math.gcd(C, D)
ans = (B - A + 1)\
      - (B // C - A // C)\
      - (B // D - A // D)\
      + (B // X - A // X)
if A % C == 0:
      ans -= 1
if A % D == 0:
      ans -= 1
if A % X == 0:
      ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import math

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

def andiv(M,N):
    return((N//M) * (M-1) + N%M)

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

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(int(E-F))

Submission status: Runtime Error

Solution code:
import math

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

def andiv(M,N):  #N以下でMで割り切れないものの数
    return((N//M) * (M-1) + N%M)

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

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Submission status: Runtime Error

Solution code:
import math

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

def andiv(M,N):
    return((N//M)*(M-1)+N%M)

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

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Submission status: Runtime Error

Solution code:
import math

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

def andiv(M,N): #N以下でMで割り切れないものの数
    return((N//M)*(M-1)+N%M)

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

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Submission status: Runtime Error

Solution code:
import math

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

def andiv(A,N): #N以下でAで割り切れないものの数
    return((N//A)*(A-1)+N%A)

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

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Submission status: Runtime Error

Solution code:
import math

def lcm(a,b):
    res = a*b / math.gcd(a,b)
    return res
def ll(x,y,z):
    res = x
    res -= x/y
    res -= x/z
    res += x/lcm(y,z)
    return res
A, B, C, D = map(int, input().split())
ans = ll(B,C,D) - ll(A-1,C,D)
print(int(ans))

Submission status: Runtime Error

Solution code:
import math

def lcm(a,b):
    res = a*b / math.gcd(a,b)
    return res


def ll(x,y,z):
    res = x
    res -= x/y
    res -= x/z
    res += x/lcm(y,z)
    return res


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

Submission status: Runtime Error

Solution code:
#131c
#整数 A,B,C,D が与えられます。A 以上 B 以下の整数のうち、C でも Dでも割り切れないものの個数を求めてください。
#1≤A≤B≤10^18
#1≤C,D≤10^9

#最大公約数
import fractions

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

A,B,C,D = map(int, input().split())
#A 以上 B 以下の整数…最大10^18個
#print([i for i in range(A,B+1)])
#print(B-A+1)
#print("B:",math.floor(B/C),math.floor(B/D),math.floor(B/(D*C)))
#print("A:",math.ceil(A/C),math.ceil(A/D),math.ceil(A/(D*C)))
#print("B-A+1:",math.floor(B/C)-math.ceil(A/C)+1,math.floor(B/D)-math.ceil(A/D)+1,math.floor(B/(lcm(C, D)))-math.ceil(A/lcm(C, D))+1)

print(B-A+1-((math.floor(B/C)-math.ceil(A/C)+1)+(math.floor(B/D)-math.ceil(A/D)+1)-(math.floor(B/(lcm(C, D)))-math.ceil(A/(lcm(C, D)))+1)))

Submission status: Runtime Error

Solution code:
#131c
#整数 A,B,C,D が与えられます。A 以上 B 以下の整数のうち、C でも Dでも割り切れないものの個数を求めてください。
#1≤A≤B≤10^18
#1≤C,D≤10^9

import math

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

A,B,C,D = map(int, input().split())
#A 以上 B 以下の整数…最大10^18個
#print([i for i in range(A,B+1)])
#print(B-A+1)
#print("B:",math.floor(B/C),math.floor(B/D),math.floor(B/(D*C)))
#print("A:",math.ceil(A/C),math.ceil(A/D),math.ceil(A/(D*C)))
#print("B-A+1:",math.floor(B/C)-math.ceil(A/C)+1,math.floor(B/D)-math.ceil(A/D)+1,math.floor(B/(lcm(C, D)))-math.ceil(A/lcm(C, D))+1)

print(B-A+1-((math.floor(B/C)-math.ceil(A/C)+1)+(math.floor(B/D)-math.ceil(A/D)+1)-(math.floor(B/(lcm(C, D)))-math.ceil(A/(lcm(C, D)))+1)))

Submission status: Runtime Error

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

list_check = list(range(a, b + 1))
list_check = [x%(c*d) for x in list_check]

dic = {}
for i in list_check:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

score = 0
for i in dic:
    if i%c != 0 and i%d != 0:
        score += dic[i]

print(score)

Submission status: Runtime Error

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

def gcd_strategy():
    import math
    import fractions
    return math.gcd if hasattr(math, "gcd") else fractions.gcd


gcd = gcd_strategy()


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


c_multiple_last = b // c
d_multiple_last = b // d
cd_multiple_last = b // lcm(c, d)

for i in range(a, b+1):
    if i % c == 0 and c_flag == 0:
        c_multiple_first = i // c
        c_flag = 1
    if i % d == 0 and d_flag == 0:
        d_multiple_first = i // d
        d_flag = 1
    if i % lcm(c, d) == 0 and cd_flag == 0:
        cd_multiple_first = i // lcm(c, d)
        cd_flag = 1
    if c_flag == 1 and d_flag == 1 and cd_flag == 1:
        break

c_count = c_multiple_last - c_multiple_first + 1
d_count = d_multiple_last - d_multiple_first + 1
cd_count = cd_multiple_last - cd_multiple_first + 1

a_to_b_count = b - a + 1
ans = a_to_b_count - (c_count + d_count - cd_count)
print(ans)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
c_flag = 0
d_flag = 0
cd_flag = 0


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


c_multiple_last = b // c
d_multiple_last = b // d
cd_multiple_last = b // lcm(c, d)

for i in range(a, b+1):
    if i % c == 0 and c_flag == 0:
        c_multiple_first = i // c
        c_flag = 1
    if i % d == 0 and d_flag == 0:
        d_multiple_first = i // d
        d_flag = 1
    if i % lcm(c, d) == 0 and cd_flag == 0:
        cd_multiple_first = i // lcm(c, d)
        cd_flag = 1
    if c_flag == 1 and d_flag == 1 and cd_flag == 1:
        break

c_count = c_multiple_last - c_multiple_first + 1
d_count = d_multiple_last - d_multiple_first + 1
cd_count = cd_multiple_last - cd_multiple_first + 1

a_to_b_count = b - a + 1
ans = a_to_b_count - (c_count + d_count - cd_count)
print(ans)

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
c_flag = 0
d_flag = 0
cd_flag = 0


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


c_multiple_last = b // c
d_multiple_last = b // d
cd_multiple_last = b // lcm(c, d)

for i in range(a, b+1):
    if i % c == 0 and c_flag == 0:
        c_multiple_first = i // c
        c_flag = 1
    if i % d == 0 and d_flag == 0:
        d_multiple_first = i // d
        d_flag = 1
    if i % lcm(c, d) == 0 and cd_flag == 0:
        cd_multiple_first = i // lcm(c, d)
        cd_flag = 1
    if c_flag == 1 and d_flag == 1 and cd_flag == 1:
        break

c_count = c_multiple_last - c_multiple_first + 1
d_count = d_multiple_last - d_multiple_first + 1
cd_count = cd_multiple_last - cd_multiple_first + 1

a_to_b_count = b - a + 1
ans = a_to_b_count - (c_count + d_count - cd_count)
print(ans)

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
li=[]
for i in [a-1,b]:
    bc = i//c
    bd = i//d
    gc = c*d / math.gcd(c,d)
    cd = i//gc
    li.append(i-(bc+bd-cd))
print(int(li[1]-li[0]))

Submission status: Runtime Error

Solution code:
import math
a,b,c,d = map(int,input().split())
li=[]
for i in [a-1,b]:
    bc = i//c
    bd = i//d
    gcd = c*d / math.gcd(c,d)
    cd = i//gcd
    li.append(i-(bc+bd-cd))
print(int(li[1]-li[0]))

Submission status: Runtime Error

Solution code:
import math

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

def andiv(A,N): #N以下でAで割り切れないものの数
    return((N//A)*(A-1)+N%A)

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

E = andiv(C,B) + andiv(D,B) - andiv(lcm(C,D),B)
F = andiv(C,A-1) + andiv(D,A-1) - andiv(lcm(C,D),A-1)

print(E-F)

Submission status: Runtime Error

Solution code:
import math
import sys

l, r, c, d = map(int, sys.stdin.readline().split())

count = 0

first = (l + c - 1)//c 
last = r//c 

count += last - first + 1

first = (l + d - 1)//d 
last = r//d 
count += last - first + 1

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

first = (l + lcm - 1)//lcm 
last = r // lcm
count -= last - first + 1


print(r - l - count + 1)

Submission status: Runtime Error

Solution code:
import math

l, r, c, d = map(int, input().split())
# numbers = [True]*(r+1)


count = 0

first = (l + c - 1)//c 
last = r//c 

count += last - first + 1

first = (l + d - 1)//d 
last = r//d 
count += last - first + 1

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

first = (l + lcm - 1)//lcm 
last = r // lcm
count -= last - first + 1


print(r - l - count + 1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from fractions import gcd
import math

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


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


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


print(cantdiv(b) - cantdiv(a - 1))

Submission status: Runtime Error

Solution code:
from fractions import gcd
import math

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


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


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Submission status: Runtime Error

Solution code:
import math

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


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


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Submission status: Runtime Error

Solution code:
import math

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


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


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Submission status: Runtime Error

Solution code:
import math

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


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


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))

Submission status: Runtime Error

Solution code:
import math

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


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


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


def cantdiv(x):
    return x - math.floor(x / c) - math.floor(x / d) + math.floor(x / lcm(c, d))


print(cantdiv(b) - cantdiv(a - 1))