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())
cd = c*d//math.gcd(c,d)
e = a-1
f = (b//c + b//d - b//(cd)) - (e//c + e//d - e//(cd))
print(b-e-f)

Submission status: Runtime Error

Solution code:
import math

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

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

a = int((A - 1) / C)
b = int(B / C)

c = int((A - 1) / D)
d = int(B / D)

l = lcm(C, D)

e = int((A - 1) / l)
f = int(B / l)

res = (B - A + 1) - ((b - a) + (d - c)) + (f - e)

print(res)

Submission status: Runtime Error

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

import math

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

ans = 0

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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

l = int(c * d // gcd(c, d))

m = int(b // c) - int((a - 1) // c) + int(b // d) - int((a - 1) // d) - int(b // l) - int((a - 1) // l)

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

import math

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

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

cntC = (B // C) - (A // C)
cntD = (B // D) - (A // D)
cntCD = (B // CD) - (A // CD)

if A % C == 0:
    cntC += 1
if A % D == 0:
    cntD += 1
if A % CD == 0:
    cntCD += 1

ans = B - A + 1 - (cntC + cntD - cntCD)
print(ans)

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)

C_comp = B // C - (A-1) // C
D_comp = B // D - (A-1) // D
CD_comp = B // lcm(C,D) - (A-1) // lcm(C,D)

print((B - A + 1) - (C_comp + D_comp - CD_comp))

Submission status: Runtime Error

Solution code:
import math
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 = C * D / math.gcd(C, D)
E_ = int(B/E) - int(A/E)

ans = B - A + 1 - C_ - D_ + E_
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
from sys import stdin
import sys, math
import numpy as np

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

def main():
    a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
    #print(a, b, c, d)
    #bまでで3で割り切れる数
    three_all = b // c
    #a-1までで3で割り切れる数
    three_less = (a-1) // c
    three_range = three_all - three_less
    
    two_all = b // d
    two_less = (a-1) // d
    two_range = two_all - two_less
    
    z = lcm(c,d)
    six_all = b // z
    six_less = (a-1) // z
    six_range = six_all - six_less
    
    num = three_range + two_range - six_range
    
    ans = b-a+1-num
    print(ans)
    
    return(ans)

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)

b_num = b - b//c - b//d + b//lcm
a_num = a - a//c - a//d + a//lcm

ans = b_num - a_num + 1

print(int(ans))

Submission status: Runtime Error

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

import math
a, b, c, d = map(int,input().split())
a = a-1
dc = b//c
dc -= a//c

dd = b//d
dd -= a//d

lcm = c*d//math.gcd(c,d)
dcd = b//lcm
dcd -= a//lcm

ans = b-a-dc-dd+dcd

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())
target = B - A + 1

hoge1 = int(B / C) - int((A - 1) / C)
hoge2 = int(B / D) - int((A - 1) / D)
hoge3 = int(B / (C * D)) - int((A - 1) / (C * D))

saisho = lcm(C, D)
hoge4 = B // saisho - (A - 1) // saisho

print(target - hoge1 - hoge2 + hoge4)

Submission status: Runtime Error

Solution code:
from math import *
from fractiosn import *
a,b,c,d=map(int,raw_input().split())
lcm=lambda x,y: x*y//gcd(x,y)

def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    print (b-a+1) - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d))
else:
    print 0

Submission status: Runtime Error

Solution code:
def unchi(x,m,n):
  r=x//m+x//n-x//(m＊n)
  return r
a,b,c,d=(int(i) for i in input().split())
print(unchi(b,c,d)-unchi(a,c,d))

Submission status: Runtime Error

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

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

a_div_c = a//c
ac_mod = a%c
bc = b//c

a_div_d = a//d
ad_mod = a%d
bd = b//d

a_div_lcm_cd = a//lcm_cd
alcm_cd_mod = a%lcm_cd
blcm_cd = b//lcm_cd

cnt_c = 0
cnt_d = 0
cnt_lcmcd = 0

cnt_c = (bc-a_div_c)
if not ac_mod:
    cnt_c+=1

cnt_d = (bd-a_div_d)
if not ad_mod:
    cnt_d+=1

cnt_lcmcd = (blcm_cd-a_div_lcm_cd)
if not alcm_cd_mod:
    cnt_lcmcd+=1
print(b-a+1-(cnt_c+cnt_d-cnt_lcmcd))

Submission status: Runtime Error

Solution code:
import math
A, B, C, D = list(map(int, input().split()))
A_ = A - 1
B_res = B - (B//C + B//D - B//int(C*D/math.gcd(C, D)))
A_res = A_ - (A_//C + A_//D - A_//int(C*D/math.gcd(C, D)))
print(B_res - A_res)

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().strip().split())

a_c = A // C
a_c_mod = A % C
b_c = B // C
a_d = A // D
a_d_mod = A % D
b_d = B // D

l = lcm(C, D)

a_cd = A // l
a_cd_mod = A % l
b_cd = B // l

if a_c_mod == 0:
    a_c -= 1

if a_d_mod == 0:
    a_d -= 1

if a_cd_mod == 0:
    a_cd -= 1

print((B - A + 1) - (b_c - a_c) - (b_d - a_d) + (b_cd + a_cd))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(4100000)
import math
a,b,c,d = [int(i) for i in input().split()]
lcm = (c * d) // math.gcd(c, d)
# a = 9-9//2-9//3+9//lcm
# b = 4-4//2-4//3+4//lcm
a -= 1
e = b-b//c-b//d+b//lcm
f = a-a//c-a//d+a//lcm
print(e-f)

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

a = (A - 1) // C
b = B // C

c = (A - 1) // D
d = B // D

l = lcm(C, D)

e = (A - 1) // l
f = B // l

res = (B - A + 1) - ((b - a) + (d - c)) + (f - e)

print(res)

Submission status: Runtime Error

Solution code:
def unchi(x,m,n):
  a=x//m+x//n-x//(m＊n)
  return a
a,b,c,d=(int(i) for i in input().split())
print(unchi(b,c,d)-unchi(a,c,d))

Submission status: Runtime Error

Solution code:
import math

#n = int(input())
a, b, c, d = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = input()
#list = list(s)

kotae = 0

kaisic = int(a / c)
owaric = int(b / c)
kaisid = int(a / d)
owarid = int(b / d)
e = c * d / math.gcd(c, d)
kaisie = int(a / (e))
owarie = int(b / (e))

countc = owaric - kaisic + 1
if (kaisic * c != a) :
    countc -= 1

countd = owarid - kaisid + 1
if (kaisid * d != a) :
    countd -= 1

counte = owarie - kaisie + 1
if (kaisie * e != a) :
    counte -= 1


print(b - a + 1 - (countc + countd - counte))

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
nc=math.floor(b/c)-math.ceil(a/c)+1
nd=math.floor(b/d)-math.ceil(a/d)+1
min=c*d/math.gcd(c,d)
ncd=math.floor(b/min)-math.ceil(a/min)+1
print(b-a+1-(nc+nd-ncd))

Submission status: Runtime Error

Solution code:
from math import *
a,b,c,d=map(int,input().split())
lcm=lambda x,y:x*y//gcd(x,y)
def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)

if c != 1 and d != 1:
    print ((b-a+1) - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d)))
else:
    print (0)

Submission status: Runtime Error

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

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)

Submission status: Runtime Error

Solution code:
import math
na = lambda: list(map(int, input().split()))
A,B,C,D = na()
ee = (C * D)//math.gcd(C, D)
A = A-1
cc = B//C
dd = B//D
ansb = cc+dd-B//ee
ansa = A//C+A//D-A//ee
print(B-A-(ansb-ansa))

Submission status: Runtime Error

Solution code:
import math
if __name__ == "__main__":
    A,B,C,D = map(int,input().split())
    ac = A%C
    E = int(C * D / math.gcd(C,D))
    if ac == 0:
        modc = B//C - A//C + 1
    else:
        modc = B//C - A//C
    ad = A%D
    if ad == 0:
        modd = B//D - A//D + 1
    else:
        modd = B//D - A//D
    ae = A%E
    if ae == 0:
        mode = B//E - A//E + 1
    else:
        mode = B//E - A//E
    print(int(B-A+1-modc-modd+mode))

Submission status: Runtime Error

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

def gcd(n,m):
    if m>n:
        m,n=n,m
    elif m==n:
        return n
    return gcd(n-m,m)

gcd_cd = gcd(C,D)
hoge = C*D//gcd_cd
def f(x):
    #main
    c = x//C
    d = x//D
    cd = x//hoge
    ans = x + cd - c - d
    return ans

print(f(B)-f(A-1))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

def lcm(C, D):
    return (C * D) // math.gcd(C, D)

lcm_C_D = lcm(C,D)
rem_C = lcm_C_D // C
rem_D = lcm_C_D // D

lcm_count = rem_C + rem_D - 1


rem_A = A % lcm_C_D
dif_A = lcm_C_D - rem_A
count_A_C = dif_A // C
count_A_D = dif_A // D
before_count = count_A_C + count_A_D + 1



dif_B = B % lcm_C_D
count_B_C = dif_B // C
count_B_D = dif_B // D
after_count = count_B_C + count_B_D 


syou_A = (A + dif_A) // lcm_C_D
syou_B = (B - dif_B) // lcm_C_D
between_count = (syou_B - syou_A) * lcm_count


print(B - A + 1 - (after_count + between_count + before_count))

Submission status: Runtime Error

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


s = C * D / math.gcd(C, D)

p  = B - A + 1 - int((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // s - (A - 1) // s))
print(p)

Submission status: Runtime Error

Solution code:
from math import gcd, floor

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

a = (B-A+1)
b = -(floor(B/C) + floor(B/D) - floor(B/(floor(C*D/gcd(C,D)))))
c = (floor((A-1)/C) + floor((A-1)/D) - floor((A-1)/(floor(C*D/gcd(C,D)))))

print(a+b+c)

Submission status: Runtime Error

Solution code:
import math

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

a, b, c, d = [int(elem) for elem in input().split()]
print((b+1 - a) - ((b+1) // c) - ((b+1) // d) + (a // c) + (a // d) + ((b+1) // lcm(c, d)) - (a // lcm(c, d)))

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)

A_C = A // C
A_D = A // D
A_CD = A // lcm(C, D)

B_C = B // C
B_D = B // D
B_CD = B // lcm(C, D)

A_e = A - (A_C + A_D - A_CD)
B_e = B - (B_C + B_D - B_CD)

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

Submission status: Runtime Error

Solution code:
a,b,c,d=map(int,input().split())
import math
nc=math.floor(b/c)-math.ceil(a/c)+1
nd=math.floor(b/d)-math.ceil(a/d)+1
min=c*d//math.gcd(c,d)
ncd=math.floor(b/min)-math.ceil(a/min)+1
print(b-a+1-(nc+nd-ncd))

Submission status: Runtime Error

Solution code:
import math

if __name__ == "__main__":

    A,B,C,D = map(int,input().split())
    ac = A%C
    #bc = B%C
    E = int(C * D / math.gcd(C,D))
    if ac == 0:
        modc = B//C - A//C + 1
    else:
        modc = B//C - A//C
    ad = A%D
    if ad == 0:
        modd = B//D - A//D + 1
    else:
        modd = B//D - A//D
    ae = A%E
    if ae == 0:
        mode = B//E - A//E + 1
    else:
        mode = B//E - A//E
    print(int(B-A+1-modc-modd+mode))

Submission status: Runtime Error

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

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd


ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)

print(ans)

Submission status: Runtime Error

Solution code:

import math
def acinput():
    return list(map(int,input().split(" ")))

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

a,b,c,d=acinput()


l=lcm(c,d)
n_CandD=int(b/l)-int((a-1)/l)
n_C=int(b/c)-int((a-1)/c)
n_D=int(b/d)-int((a-1)/d)

print(int(b-a+1-(n_C+n_D-n_CandD)))

Submission status: Runtime Error

Solution code:
import math
def number_calc(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    return (right - left + 1)

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

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

print(ans)

Submission status: Runtime Error

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

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

e=b-a+1
x=0
if e%c!=0 or e%d!=0 or e%lcm(c,d):x-=1
s=((e//c)+(e//d)-(e//lcm(c,d)))
ans=e-s
print(ans+x)

Submission status: Runtime Error

Solution code:
from math import gcd

def lcm(n,m):
    return (n*m)//gcd(n,m)

def main():
    a,b,c,d=map(int,input().split())
    num=b-a+1
    moda1=(a-1)//c
    moda2=(a-1)//d
    moda3=(a-1)//(lcm(c,d))
    modat=moda1+moda2-moda3
    modb1=b//c
    modb2=b//d
    modb3=b//(lcm(c,d))
    modbt=modb1+modb2-modb3
    mod=modbt-modat
    return num-mod

print(main())

Submission status: Runtime Error

Solution code:
import math

a, b, c, d = map(int, input().split())
ran = b - a + 1
if a % c == 0:
    count1 = math.ceil(ran / c)
else:
    count1 = math.ceil((ran - (c - a % c)) / c)
if a % d == 0:
    count2 = math.ceil(ran / d)
else:
    count2 = math.ceil((ran - (d - a % d)) / d)
e = c * d / math.gcd(c, d)
if a % e == 0:
    count3 = math.ceil(ran / e)
else:
    count3 = math.ceil((ran - (e - a % e)) / e)
print(ran - (count1 + count2 - count3))

Submission status: Runtime Error

Solution code:
import math

def fai(n, x, y):
    g = math.gcd(x, y)
    l = x * (y//g)
    return n - (n//x) - (n//y) + (n//l)

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

alpha = 0
if a%c != 0 and a%d != 0:
    alpha = 1

print(fai(b, c, d) - fai(a, c, d) + alpha)

Submission status: Runtime Error

Solution code:
# coding: utf-8
from sys import stdin
import sys, math
import numpy as np

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

def main():
    a,b,c,d = [int(x) for x in stdin.readline().rstrip().split()]
    #print(a, b, c, d)
    #bまでで3で割り切れる数
    three_all = b // c
    #a-1までで3で割り切れる数
    three_less = (a-1) // c
    three_range = three_all - three_less
    
    two_all = b // d
    two_less = (a-1) // d
    two_range = two_all - two_less
    
    z = lcm(c,d)
    six_all = b // z
    six_less = (a-1) // z
    six_range = six_all - six_less
    
    num = three_range + two_range - six_range
    
    ans = b-a+1-num
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import numpy as np
import math

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

c = B//C - (A-1)//C
d = B//D - (A-1)//D

CD = C * D // math.gcd(C, D)
cd = B//CD - (A-1)//CD

ans = B - (A-1) - (c + d - cd)
ans = int(ans)

print(ans)

Submission status: Runtime Error

Solution code:
#
import sys
import math
import numpy as np
import itertools

def gcd(m,n):
    p=max(m,n)
    q=min(m,n)
    if p % q == 0:
        return q
    else:
        return gcd(q,p%q)



# いくつか入力
a,b,c,d = (int(i) for i in input().split())  

x = b // c - (a-1) // c
y = b // d - (a-1) // d
e = c * d // lcm(c,d)
z = b // e - (a-1) // e

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

Submission status: Runtime Error

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

import math
G = math.gcd(C, D)

A_B = []
for AB in [A-1, B]:
  AB_c = AB // C
  AB_d = AB // D
  AB_g = AB // G
  A_B.append(AB_c + AB_d - AB_g)
can_divide = A_B[1] - A_B[0]
ans = (B - (A-1)) - can_divide
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
from math import ceil, gcd


def divs_count(start, end, mod):
    return (end // mod) - ceil(start / mod) + 1


def solve(A: int, B: int, C: int, D: int):
    ans = (
        B
        - A
        + 1
        - (divs_count(A, B, C) + divs_count(A, B, D) - divs_count(A, B, (C * D)//gcd(C, D)))
    )
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(A, B, C, D)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

a_c = (a-1)//c
a_d = (a-1)//d
gcd_dc = math.gcd(d,c)
lcm_dc = (c*d)//gcd_dc
a_cd = (a-1)//lcm_dc
b_c = b//c
b_d = b//d
b_cd = b//lcm_dc

print(b-a+1-(b_c+b_d-b_cd-a_c-a_d+a_cd))

Submission status: Runtime Error

Solution code:
from math import gcd

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

a = (B-A+1)
b = -(B//C + B//D - B//(C*D//gcd(C,D)))
c = ((A-1)//C + (A-1)//D - (A-1)//(C*D//gcd(C,D)))

print(a+b+c)

Submission status: Runtime Error

Solution code:
# C問題
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)
ac = A // C
bc = B // C
ad = A // D
bd = B // D
ae = A // E
be = B // E
xx = bc - ac + bd - ad
yy = be - ae
print(B - A + 1 - xx + yy)

Submission status: Runtime Error

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

cko = math.floor(b/c) - math.ceil(a/c) + 1
dko = math.floor(b/d) - math.ceil(a/d) + 1
cdko = math.floor(b/e) - math.ceil(a/e) + 1
print(b-a+1-cko-dko+cdko)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

C_div = B//C - (A-1)//C
D_div = B//D - (A-1)//D
CandD = int(C*D/math.gcd(C, D))
CandD_div = B//CandD - (A-1)//CandD

print(B-(A-1)-C_div-D_div+CandD_div)

Submission status: Runtime Error

Solution code:
import math

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

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

B = 0
B += b//c
B += b//d
B -= b//lcm(c, d)

A = 0
A += a//c
A += a//d
A -= a//lcm(c, d)

ans = (b-a) - (B - A)
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())
#A = list(map(int,input().split()))

c_b  = B//C
d_b  = B//D
cd_b = B//lcm(C,D)

c_a  = (A-1)//C
d_a  = (A-1)//D
cd_a = (A-1)//lcm(C,D)

ans = (B - c_b - d_b + cd_b) - (A - 1 - c_a - d_a + cd_a)



print(str(ans))

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)


a_c = (a-1)//c
b_c = b//c
a_d = (a-1)//d
b_d = b//d
a_cd = (a-1)//lcm(c, d)
b_cd = b//lcm(c, d)

ans = (b - a + 1) - (b_c - a_c) - (b_d - a_d) + (b_cd - a_cd)

print(ans)

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)

s = lcm(C, D)	

p  = B - A + 1 - int((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // s - (A - 1) // s))
print(p)

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())
a = B//C-(A-1)//C
b = B//D-(A-1)//D
c  =lcm(C,D)
d = B//c-(A-1)//c
e = B - A +1 - a -b + d 
print(e)

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
ac = a // c
ad = a // d
acd = a // cd
bc = b // c
bd = b // d
bcd = b // cd

ans = (b - a) - (bc + bd - bcd - (ac + ad - acd))
print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd

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


print((B-A+1) - (B//C + B//D - B//(C*D//gcd(C,D))) + ((A-1)//C + (A-1)//D - (A-1)//(C*D//gcd(C,D))))

Submission status: Runtime Error

Solution code:
import numpy as np

def f(X, C, D):
    return X - X//C - X//D + X//np.lcm(C,D)


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

    ans = f(B, C, D) - f(A-1, C, D)
    print(ans)


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)

bb = ((b // c) + (b // d) - (b // lcm))

aa = ((a // c) + (a // d) - (a // lcm))

print((b-a) - int(bb-aa) + 1)

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
from math import *
a,b,c,d=map(int,input().split())
lcm=lambda x,y:x*y//gcd(x,y)
def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)
if b >= a:
    if c != 1 and d != 1:
        print ((b-a+1) - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d)))
    else:
        print (0)
else:
    print (0)

Submission status: Runtime Error

Solution code:
import numpy as np

def acinput():
    return list(map(int,input().split(" ")))

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

a,b,c,d=acinput()


l=lcm(c,d)
n_CandD=int(b/l)-int((a-1)/l)
n_C=int(b/c)-int((a-1)/c)
n_D=int(b/d)-int((a-1)/d)

print(int(b-a+1-(n_C+n_D-n_CandD)))

Submission status: Runtime Error

Solution code:
from math 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

ans -= -int(a/c) + int(b/c)
ans -= -int(a/d) + int(b/d)
ans += -int(a/temp) + int(b / temp)

print(int(ans))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

import sys
import math

def f(n,m):
    nm = n % m
    if nm==0: return n
    else: return n + m - nm
#
a,b,c,d = [ int(x) for x in sys.stdin.readline().split() ]
cd = c * d // math.gcd(c,d)

# nc
aa = f(a,c)
if aa>b: nc=0
else: nc= (b-aa)//c + 1

# nd
aa = f(a,d)
if aa>b: nd=0
else: nd= (b-aa)//d + 1

# ncd
aa = f(a,cd)
if aa>b: ncd= 0
else: ncd= (b-aa)//cd + 1
#
print( b-a+1 - ( nc + nd - ncd ) )

Submission status: Runtime Error

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


import math

def f(a, b, c):
    return b//c - (a-1)//c


def main():
    A,B,C,D = map(int, input().split())
    
    x = B - A + 1 - f(A,B,C) - f(A, B, D) + f(A, B, C*D//math.gcd(C, D))
    print(x)





if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from math import *
lcm = lambda x, y: x * y // gcd(x, y)
def solve():
    a, b, c, d = map(int, input().split())
    C = len(range(ceil(a / c) * c, b + 1, c))
    D = len(range(ceil(a / d) * d, b + 1, d))
    cd = lcm(c, d)
    CD = len(range(ceil(a / cd) * cd, b + 1, cd))
    print(b - a + 1 - (C + D - CD))
solve()

Submission status: Runtime Error

Solution code:
import math

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

count = 0
i = A
d = B - A

ta = d // C
tb = d // D
tc = d//(C * D // math.gcd(C, D))

print(d-(ta+tb-tc))

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)

s = lcm(C, D)	
print(B - A + 1 - int((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // s - (A - 1) // s)))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def not_divided(x, A, B):
    if x > B:
        return 0
    lower = math.ceil(A / x)
    upper = math.floor(B / x)
    num = upper - lower + 1
    return num

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

    # not divided by C
    C_num = not_divided(C, A, B) 
    D_num = not_divided(D, A, B) 

    CD = C * D // math.gcd(C, D)
    CD_num = not_divided(CD, A, B)

    C_or_D_num = C_num + D_num - CD_num

    num = (B - A + 1) - C_or_D_num

    print(num)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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


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

Submission status: Runtime Error

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


def do():
    A,B,C,D =  list(map(int,input().split(" ")))
    CD = lcm(C,D)
    A1 = A- 1
    ans = (B//C + B//D - B//CD) - (A1//C + A1//D - A1//CD)
    ans = (B-A+1) - ans
    print(ans)

if __name__ == "__main__":
    do()

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

# B以下で割り切れる
UB_C = B // C
UB_D = B // D
UB_CD = B // lcm(C, D)

UB = B - (UB_C + UB_D - UB_CD)

# A以下で割り切れる
UA_C = A // C
UA_D = A // D
UA_CD = A // lcm(C, D)

UA = A - (UA_C + UA_D - UA_CD)

ans = UB - UA

if A % C != 0 and A % D != 0:
    ans += 1

print(ans)

Submission status: Runtime Error

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

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

tgC = int(B/C) - int((A-1)/C)
tgD = int(B/D) - int((A-1)/D)
tgCD = int(B/CD) - int((A-1)/CD)


print((B-A+1)-(tgC+tgD-tgCD))

Submission status: Runtime Error

Solution code:
from math import *
a,b,c,d=map(int,input().split())
lcm=lambda x,y:x*y//gcd(x,y)
def f(a,b,c):
    return (b - a + 1) // c + (1 if b % c <= a % c else 0)
if c != 1 and d != 1:
    print ((b-a+1) - f(a,b,c) - f(a,b,d) + f(a,b,lcm(c,d)))
else:
    print (0)

Submission status: Runtime Error

Solution code:
import math

def solve():
  A, B, C, D = map(int, input().split())
  A = A - 1
  CD = C * D // math.gcd(C, D)
  num_C = (B // C) - (A // C)
  num_D = (B // D) - (A // D)
  num_CD = (B // CD) - (A // CD)
  return B - A - num_C - num_D + num_CD

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

B_C = B // C
B_D = B // D
B_C_D = B // lcm(C, D)

A_C = (A - 1) // C
A_D = (A - 1) // D
A_C_D = (A - 1) // lcm(C, D)

B_div = B_C + B_D - B_C_D
A_div = A_C + A_D - A_C_D



print(B - A + 1 - (B_div - A_div))

Submission status: Runtime Error

Solution code:
import math
#[N,K] = list(map(int,input().split()))
#A = list(map(int,input().split()))
#[A,B,C,D] = list(map(int,input().split()))
[A,B,C,D] = list(map(int,input().split()))
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
x_c = (B//C) - ((A-1)//C)
x_d = (B//D) - ((A-1)//D)
x_cd = (B//lcm(C,D)) - ((A-1)//lcm(C,D))
ans = (B - A + 1) - (x_c + x_d -x_cd)
print(ans)

Submission status: Runtime Error

Solution code:


import math
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

A,B,C,D = na()
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
ee = lcm(C,D)
A = A-1
cc = B//C
dd = B//D
ansb = cc+dd-B//ee

ansa = A//C+A//D-A//ee

print(B-A-(ansb-ansa))

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)
    
l_c = int((a-1)/c)
l_d = int((a-1)/d)
l_c_d = int((a-1)/lcm(c, d))

l_ans = a - 1 - (l_c + l_d - l_c_d)


g_c = int(b/c)
g_d = int(b/d)
g_c_d = int(b/lcm(c, d))
g_ans = b - (g_c + g_d - g_c_d)

print(g_ans - l_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())
B += 1

X1 = A - ((A // C) + (A // D) - (A // lcm(C, D)))
X2 = B - ((B // C) + (B // D) - (B // lcm(C, D)))
print(X2 - X1)

Submission status: Runtime Error

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


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

Submission status: Runtime Error

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


def number(A,B,x):
    left = math.ceil(A/x)
    right = math.floor(B/x)
    return (right - left + 1)
    
ans = B-A+1
ans -=number(A,B,C)
ans -=number(A,B,D)
ans +=number(A,B,(C*D)/math.gcd(C,D))

print(ans)

Submission status: Runtime Error

Solution code:

ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

A,B,C,D = na()
from functools import reduce


def gcd(*numbers):
    """
    Return the greatest common divisor of 1 or more integers
    Examples
    --------
    >>> gcd(5)
    5
    >>> gcd(30, 40)
    10
    >>> gcd(120, 40, 60)
    20
    """
    # Am I terrible for doing it this way?
    from math import gcd

    return reduce(gcd, numbers)



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

    return reduce(lcm, numbers, 1)
ee = lcm(C,D)
A = A-1
cc = B//C
dd = B//D
ansb = cc+dd-B//ee

ansa = A//C+A//D-A//ee

print(B-A-(ansb-ansa))

Submission status: Runtime Error

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

lcm = C * D //math.gcd(C, D)
b =  B // C + B // D - B // lcm
b = B - b

A -= 1
a =  A // C + A // D - A // lcm
a = A - a

print(b - a)