package main import ( "bufio" "fmt" "os" "sort" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var wr = bufio.NewWriter(os.Stdout) func out(x ...interface{}) { fmt.Fprintln(wr, x...) } func getI() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getF() float64 { sc.Scan() i, e := strconv.ParseFloat(sc.Text(), 64) if e != nil { panic(e) } return i } func getInts(N int) []int { ret := make([]int, N) for i := 0; i < N; i++ { ret[i] = getI() } return ret } func getS() string { sc.Scan() return sc.Text() } // min, max, asub, absなど基本関数 func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b } func asub(a, b int) int { if a > b { return a - b } return b - a } func abs(a int) int { if a >= 0 { return a } return -a } func lowerBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] >= x }) return idx } func upperBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] > x }) return idx } type UnionFind struct { n int par []int } func newUnionFind(n int) *UnionFind { uf := new(UnionFind) uf.n = n uf.par = make([]int, n) for i, _ := range uf.par { uf.par[i] = -1 } return uf } func (uf UnionFind) root(x int) int { if uf.par[x] < 0 { return x } uf.par[x] = uf.root(uf.par[x]) return uf.par[x] } func (uf UnionFind) unite(x, y int) { rx, ry := uf.root(x), uf.root(y) if rx != ry { if uf.size(rx) > uf.size(ry) { rx, ry = ry, rx } uf.par[ry] += uf.par[rx] uf.par[rx] = ry } } func (uf UnionFind) same(x, y int) bool { return uf.root(x) == uf.root(y) } func (uf UnionFind) size(x int) int { return -uf.par[uf.root(x)] } func (uf UnionFind) groups() [][]int { rootBuf, groupSize := make([]int, uf.n), make([]int, uf.n) for i := 0; i < uf.n; i++ { rootBuf[i] = uf.root(i) groupSize[rootBuf[i]]++ } res := make([][]int, uf.n) for i := 0; i < uf.n; i++ { res[i] = make([]int, 0, groupSize[i]) } for i := 0; i < uf.n; i++ { res[rootBuf[i]] = append(res[rootBuf[i]], i) } result := make([][]int, 0, uf.n) for i := 0; i < uf.n; i++ { if len(res[i]) != 0 { r := make([]int, len(res[i])) copy(r, res[i]) result = append(res, r) } } return result } func main() { defer wr.Flush() sc.Split(bufio.ScanWords) sc.Buffer([]byte{}, 1000000) // this template is new version. // use getI(), getS(), getInts(), getF() L, R := getI(), getI() uf := newUnionFind(R + 1) for i := L; i <= R; i++ { for j := i + i; j <= R; j += i { uf.unite(i, j) } } root := uf.root(L) cnt := 0 for i := L; i <= R; i++ { if uf.root(i) != root { uf.unite(L, i) cnt++ } } out(cnt) }