Use this to learn the idea, then write your own version.
1package main2 3import (4 "bufio"5 . "fmt"6 "io"7)8 9var d920 [1e6 + 1]int10 11type seg920 []struct {12 l, r int13 s int6414 fixed bool15}16 17func (t seg920) _pushUp(o int) {18 lo, ro := t[o<<1], t[o<<1|1]19 t[o].s = lo.s + ro.s20 t[o].fixed = lo.fixed && ro.fixed21}22 23func (t seg920) _build(a []int, o, l, r int) {24 t[o].l, t[o].r = l, r25 if l == r {26 t[o].s = int64(a[l-1])27 t[o].fixed = a[l-1] <= 228 return29 }30 m := (l + r) >> 131 t._build(a, o<<1, l, m)32 t._build(a, o<<1|1, m+1, r)33 t._pushUp(o)34}35 36func (t seg920) _update(o, l, r int) {37 to := &t[o]38 if to.fixed {39 return40 }41 if to.l == to.r {42 to.s = int64(d920[to.s])43 to.fixed = to.s <= 244 return45 }46 m := (to.l + to.r) >> 147 if l <= m {48 t._update(o<<1, l, r)49 }50 if m < r {51 t._update(o<<1|1, l, r)52 }53 t._pushUp(o)54}55 56func (t seg920) _query(o, l, r int) (s int64) {57 ol, or := t[o].l, t[o].r58 if l <= ol && or <= r {59 return t[o].s60 }61 m := (ol + or) >> 162 if l <= m {63 s += t._query(o<<1, l, r)64 }65 if m < r {66 s += t._query(o<<1|1, l, r)67 }68 return69}70 71func (t seg920) init(a []int) { t._build(a, 1, 1, len(a)) }72func (t seg920) update(l, r int) { t._update(1, l, r) }73func (t seg920) query(l, r int) int64 { return t._query(1, l, r) }74 7576func CF920F(_r io.Reader, _w io.Writer) {77 in := bufio.NewReader(_r)78 out := bufio.NewWriter(_w)79 defer out.Flush()80 const mx = 1e681 for i := 1; i <= mx; i++ {82 for j := i; j <= mx; j += i {83 d920[j]++84 }85 }86 87 var n, q, op, l, r int88 Fscan(in, &n, &q)89 a := make([]int, n)90 for i := range a {91 Fscan(in, &a[i])92 }93 t := make(seg920, 4*n)94 t.init(a)95 for ; q > 0; q-- {96 if Fscan(in, &op, &l, &r); op == 1 {97 t.update(l, r)98 } else {99 Fprintln(out, t.query(l, r))100 }101 }102}103 104