Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he has m queries:  Query number i is represented as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n).  The answer to the query li, ri is the number of pairs of integers q, w (li ≤ q, w ≤ ri) such that pq is the divisor of pw. Help Yaroslav, answer all his queries.

The first line contains the integers n and m (1 ≤ n, m ≤ 2·105). The second line contains n distinct integers p1, p2, ..., pn (1 ≤ pi ≤ n). The following m lines contain Yaroslav's queries. The i-th line contains integers li, ri (1 ≤ li ≤ ri ≤ n).

Print m integers — the answers to Yaroslav's queries in the order they appear in the input. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

package main

import (
	"bufio"
	"bytes"
	"os"
	"sort"
	"strconv"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getWord() string {
	var (
		buf bytes.Buffer
		ch  byte
	)
	for (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') {
		ch, _ = stdinBuffer.ReadByte()
	}
	for (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') {
		buf.WriteByte(ch)
		ch, _ = stdinBuffer.ReadByte()
	}
	return buf.String()
}

func getInt() (ret int) {
	s := getWord()
	for _, v := range s {
		ret *= 10
		ret += int(v - '0')
	}
	return
}

// Puts

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = getInt()
	m := getInt()
	a := make([]int, n)
	for i := range a {
		a[i] = getInt()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = getInt(), getInt()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	defer stdoutBuffer.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

const MAX_N = 200005

func read_ints(in *bufio.Reader) []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i := range words {
		a[i], _ = strconv.Atoi(words[i])
	}
	return a
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	in := bufio.NewReader(os.Stdin)
	m := read_ints(in)[1]
	a := read_ints(in)
	n = len(a)
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		x := read_ints(in)
		q[i].l, q[i].r = x[0], x[1]
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, i*j)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}

package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
	"strings"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getIntSlice() []int {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.Atoi(tmp[i])
	}
	return ret
}

func scanInt(a ...*int) {
	b := getIntSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	var m int
	scanInt(&n, &m)
	a := getIntSlice()
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		scanInt(&q[i].l, &q[i].r)
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	stdoutBuffer.Flush()
}

package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
)

const MAX_N = 200005

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func read_int() (x int) {
	var ch byte
	for ch < '0' || ch > '9' {
		ch, _ = in.ReadByte()
	}
	x = int(ch - '0')
	for {
		ch, _ = in.ReadByte()
		if ch >= '0' && ch <= '9' {
			x = x*10 + int(ch-'0')
		} else {
			break
		}
	}
	return
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		out.WriteString(strconv.Itoa(v))
		out.WriteByte('\n')
		out.Flush()
	}
}

package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
)

const MAX_N = 200005

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func read_int() int {
	var ch byte
	for ch < '0' || ch > '9' {
		ch, _ = in.ReadByte()
	}
	ret := int(ch - '0')
	for {
		ch, _ = in.ReadByte()
		if ch >= '0' && ch <= '9' {
			ret = ret*10 + int(ch-'0')
		} else {
			break
		}
	}
	return ret
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		out.WriteString(strconv.Itoa(v))
		out.WriteByte('\n')
	}
	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

const MAX_N = 200005

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func read_int() int {
	var ch byte
	for ch < '0' || ch > '9' {
		ch, _ = in.ReadByte()
	}
	ret := int(ch - '0')
	for {
		ch, _ = in.ReadByte()
		if ch >= '0' && ch <= '9' {
			ret = ret*10 + int(ch-'0')
		} else {
			break
		}
	}
	return ret
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}

package main

import (
	"bufio"
	"bytes"
	"os"
	"sort"
	"strconv"
	"strings"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getInt() int {
	x := 0
	positive := true
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		if ch == '-' {
			positive = false
		}
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	if positive {
		return x
	}
	return -x
}

func getIntSlice() []int {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.Atoi(tmp[i])
	}
	return ret
}

func scanInt(a ...*int) {
	b := getIntSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getInt64() int64 {
	var x, sign int64 = 0, 1
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		if ch == '-' {
			sign = -1
		}
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int64(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	return x * sign
}

func getInt64Slice() []int64 {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int64, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.ParseInt(tmp[i], 10, 64)
	}
	return ret
}

func scanInt64(a ...*int64) {
	b := getInt64Slice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getWord() string {
	var (
		buf bytes.Buffer
		ch  byte
	)
	for ch == 0 || ch == ' ' || ch == '\n' {
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch != 0 && ch != ' ' && ch != '\n' {
		buf.WriteByte(ch)
		ch, _ = stdinBuffer.ReadByte()
	}
	return buf.String()
}

func getWordSlice() []string {
	line, _ := stdinBuffer.ReadString('\n')
	return strings.Fields(line)
}

func scanWord(a ...*string) {
	b := getWordSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getLine() string {
	line, _ := stdinBuffer.ReadString('\n')
	return strings.TrimSpace(line)
}

// Puts

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

func putInt64(v int64, sep byte) {
	stdoutBuffer.WriteString(strconv.FormatInt(v, 10))
	stdoutBuffer.WriteByte(sep)
}

func putWord(v string, sep byte) {
	stdoutBuffer.WriteString(v)
	stdoutBuffer.WriteByte(sep)
}

// Basic functions.

func unique(p *[]int) {
	a := *p
	n := len(a)
	if n > 0 {
		sort.Ints(a)
		i, j := 1, 0
		for ; i < n; i++ {
			if a[i] != a[j] {
				j++
				a[j] = a[i]
			}
		}
		*p = a[:j+1]
	}
}

// Splay tree.

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = getInt()
	m := getInt()
	a := make([]int, n)
	for i := range a {
		a[i] = getInt()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = getInt(), getInt()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	stdoutBuffer.Flush()
}

package main

import (
	"bufio"
	"bytes"
	"os"
	"sort"
	"strconv"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getWord() string {
	var (
		buf bytes.Buffer
		ch  byte
	)
	for (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && (ch < '0' || ch > '9') {
		ch, _ = stdinBuffer.ReadByte()
	}
	for (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') {
		buf.WriteByte(ch)
		ch, _ = stdinBuffer.ReadByte()
	}
	return buf.String()
}

func getInt() (ret int) {
	ret, _ = strconv.Atoi(getWord())
	return
}

// Puts

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = getInt()
	m := getInt()
	a := make([]int, n)
	for i := range a {
		a[i] = getInt()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = getInt(), getInt()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	defer stdoutBuffer.Flush()
}

package main

import (
	"bufio"
	"os"
	"sort"
)

const MAX_N = 200005

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
var outbuff = make([]byte, 20)

func read_int() (x int) {
	var ch byte
	for ch < '0' || ch > '9' {
		ch, _ = in.ReadByte()
	}
	x = int(ch - '0')
	for {
		ch, _ = in.ReadByte()
		if ch >= '0' && ch <= '9' {
			x = x*10 + int(ch-'0')
		} else {
			break
		}
	}
	return
}

func write_int(x int, end byte) {
	if x == 0 {
		out.WriteByte('0')
	} else {
		i := 0
		for ; x > 0; i++ {
			outbuff[i] = byte(x%10 + '0')
			x /= 10
		}
		for i--; i >= 0; i-- {
			out.WriteByte(outbuff[i])
		}
	}
	out.WriteByte(end)
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		write_int(v, '\n')
	}
	out.Flush()
}

package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
	"strings"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getInt() int {
	x := 0
	positive := true
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		if ch == '-' {
			positive = false
		}
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	if positive {
		return x
	}
	return -x
}

func getIntSlice() []int {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.Atoi(tmp[i])
	}
	return ret
}

// Puts

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = getInt()
	m := getInt()
	getIntSlice()
	a := getIntSlice()
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = getInt(), getInt()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	stdoutBuffer.Flush()
}

package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
)

const MAX_N = 200005

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func read_int() (x int) {
	var ch byte
	for ch < '0' || ch > '9' {
		ch, _ = in.ReadByte()
	}
	x = int(ch - '0')
	for {
		ch, _ = in.ReadByte()
		if ch >= '0' && ch <= '9' {
			x = x*10 + int(ch-'0')
		} else {
			break
		}
	}
	return
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		out.WriteString(strconv.Itoa(v))
		out.WriteByte('\n')
	}
	defer out.Flush()
}

package main

import (
	"bufio"
	"bytes"
	"os"
	"sort"
	"strconv"
	"strings"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getInt() int {
	x, sign := 0, 1
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		if ch == '-' {
			sign = -1
		}
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	return x * sign
}

func getIntSlice() []int {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.Atoi(tmp[i])
	}
	return ret
}

func scanInt(a ...*int) {
	b := getIntSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getInt64() int64 {
	var x, sign int64 = 0, 1
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		if ch == '-' {
			sign = -1
		}
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int64(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	return x * sign
}

func getInt64Slice() []int64 {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int64, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.ParseInt(tmp[i], 10, 64)
	}
	return ret
}

func scanInt64(a ...*int64) {
	b := getInt64Slice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getWord() string {
	var (
		buf bytes.Buffer
		ch  byte
	)
	for ch == 0 || ch == ' ' || ch == '\n' {
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch != 0 && ch != ' ' && ch != '\n' {
		buf.WriteByte(ch)
		ch, _ = stdinBuffer.ReadByte()
	}
	return buf.String()
}

func getWordSlice() []string {
	line, _ := stdinBuffer.ReadString('\n')
	return strings.Fields(line)
}

func scanWord(a ...*string) {
	b := getWordSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getLine() string {
	line, _ := stdinBuffer.ReadString('\n')
	return strings.TrimSpace(line)
}

// Puts

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

func putInt64(v int64, sep byte) {
	stdoutBuffer.WriteString(strconv.FormatInt(v, 10))
	stdoutBuffer.WriteByte(sep)
}

func putWord(v string, sep byte) {
	stdoutBuffer.WriteString(v)
	stdoutBuffer.WriteByte(sep)
}

// Basic functions.

func unique(p *[]int) {
	a := *p
	n := len(a)
	if n > 0 {
		sort.Ints(a)
		i, j := 1, 0
		for ; i < n; i++ {
			if a[i] != a[j] {
				j++
				a[j] = a[i]
			}
		}
		*p = a[:j+1]
	}
}

// Splay tree.

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	var m int
	scanInt(&n, &m)
	a := getIntSlice()
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		scanInt(&q[i].l, &q[i].r)
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	stdoutBuffer.Flush()
}

package main

import (
	"bufio"
	"bytes"
	"os"
	"sort"
	"strconv"
	"strings"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getInt() int {
	x := 0
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	return x
}

func getIntSlice() []int {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.Atoi(tmp[i])
	}
	return ret
}

func scanInt(a ...*int) {
	b := getIntSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getInt64() int64 {
	var x, sign int64 = 0, 1
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		if ch == '-' {
			sign = -1
		}
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int64(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	return x * sign
}

func getInt64Slice() []int64 {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int64, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.ParseInt(tmp[i], 10, 64)
	}
	return ret
}

func scanInt64(a ...*int64) {
	b := getInt64Slice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getWord() string {
	var (
		buf bytes.Buffer
		ch  byte
	)
	for ch == 0 || ch == ' ' || ch == '\n' {
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch != 0 && ch != ' ' && ch != '\n' {
		buf.WriteByte(ch)
		ch, _ = stdinBuffer.ReadByte()
	}
	return buf.String()
}

func getWordSlice() []string {
	line, _ := stdinBuffer.ReadString('\n')
	return strings.Fields(line)
}

func scanWord(a ...*string) {
	b := getWordSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getLine() string {
	line, _ := stdinBuffer.ReadString('\n')
	return strings.TrimSpace(line)
}

// Puts

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

func putInt64(v int64, sep byte) {
	stdoutBuffer.WriteString(strconv.FormatInt(v, 10))
	stdoutBuffer.WriteByte(sep)
}

func putWord(v string, sep byte) {
	stdoutBuffer.WriteString(v)
	stdoutBuffer.WriteByte(sep)
}

// Basic functions.

func unique(p *[]int) {
	a := *p
	n := len(a)
	if n > 0 {
		sort.Ints(a)
		i, j := 1, 0
		for ; i < n; i++ {
			if a[i] != a[j] {
				j++
				a[j] = a[i]
			}
		}
		*p = a[:j+1]
	}
}

// Splay tree.

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = getInt()
	m := getInt()
	a := make([]int, n)
	for i := range a {
		a[i] = getInt()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = getInt(), getInt()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	stdoutBuffer.Flush()
}

package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
)

const MAX_N = 200005

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func read_int() int {
	var ch byte
	for ch < '0' || ch > '9' {
		ch, _ = in.ReadByte()
	}
	ret := int(ch - '0')
	for {
		ch, _ = in.ReadByte()
		if ch >= '0' && ch <= '9' {
			ret = ret*10 + int(ch-'0')
		} else {
			break
		}
	}
	return ret
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		out.WriteString(strconv.Itoa(v))
		out.WriteByte('\n')
	}
	defer out.Flush()
}

package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
)

const MAX_N = 200005

var scanner = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func read_int() (x int) {
	scanner.Scan()
	x, _ = strconv.Atoi(scanner.Text())
	return
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	scanner.Split(bufio.ScanWords)
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		out.WriteString(strconv.Itoa(v))
		out.WriteByte('\n')
	}
	defer out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

const MAX_N = 200005

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func read_int() (x int) {
	var ch byte
	for ch < '0' || ch > '9' {
		ch, _ = in.ReadByte()
	}
	x = int(ch - '0')
	for {
		ch, _ = in.ReadByte()
		if ch >= '0' && ch <= '9' {
			x = x*10 + int(ch-'0')
		} else {
			break
		}
	}
	return
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}

package main

import (
	"bufio"
	"os"
	"sort"
	"strconv"
)

const MAX_N = 200005

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func read_int() (x int) {
	var ch byte
	for ch < '0' || ch > '9' {
		ch, _ = in.ReadByte()
	}
	x = int(ch - '0')
	for {
		ch, _ = in.ReadByte()
		if ch >= '0' && ch <= '9' {
			x = x*10 + int(ch-'0')
		} else {
			break
		}
	}
	return
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = read_int()
	m := read_int()
	a := make([]int, n)
	for i := range a {
		a[i] = read_int()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = read_int(), read_int()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		out.WriteString(strconv.Itoa(v))
		out.WriteByte('\n')
	}
	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

const MAX_N = 200005

func read_ints(in *bufio.Reader) []int {
	line, _ := in.ReadString('\n')
	words := strings.Fields(line)
	a := make([]int, len(words))
	for i := range words {
		a[i], _ = strconv.Atoi(words[i])
	}
	return a
}

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	in := bufio.NewReader(os.Stdin)
	m := read_ints(in)[1]
	a := read_ints(in)
	n = len(a)
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		x := read_ints(in)
		q[i].l, q[i].r = x[0], x[1]
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*j <= i; j++ {
			if i%j == 0 {
				push(i, j)
				if j*j != i {
					push(i, i/j)
				}
			}
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		fmt.Println(v)
	}
}

package main

import (
	"bufio"
	"bytes"
	"os"
	"sort"
	"strconv"
	"strings"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getInt() int {
	x, sign := 0, 1
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		if ch == '-' {
			sign = -1
		}
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	return x * sign
}

func getIntSlice() []int {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.Atoi(tmp[i])
	}
	return ret
}

func scanInt(a ...*int) {
	b := getIntSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getInt64() int64 {
	var x, sign int64 = 0, 1
	ch, _ := stdinBuffer.ReadByte()
	for ch < '0' || ch > '9' {
		if ch == '-' {
			sign = -1
		}
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch >= '0' && ch <= '9' {
		x *= 10
		x += int64(ch - '0')
		ch, _ = stdinBuffer.ReadByte()
	}
	return x * sign
}

func getInt64Slice() []int64 {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int64, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.ParseInt(tmp[i], 10, 64)
	}
	return ret
}

func scanInt64(a ...*int64) {
	b := getInt64Slice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getWord() string {
	var (
		buf bytes.Buffer
		ch  byte
	)
	for ch == 0 || ch == ' ' || ch == '\n' {
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch != 0 && ch != ' ' && ch != '\n' {
		buf.WriteByte(ch)
		ch, _ = stdinBuffer.ReadByte()
	}
	return buf.String()
}

func getWordSlice() []string {
	line, _ := stdinBuffer.ReadString('\n')
	return strings.Fields(line)
}

func scanWord(a ...*string) {
	b := getWordSlice()
	for i := range a {
		*a[i] = b[i]
	}
}

func getLine() string {
	line, _ := stdinBuffer.ReadString('\n')
	return strings.TrimSpace(line)
}

// Puts

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

func putInt64(v int64, sep byte) {
	stdoutBuffer.WriteString(strconv.FormatInt(v, 10))
	stdoutBuffer.WriteByte(sep)
}

func putWord(v string, sep byte) {
	stdoutBuffer.WriteString(v)
	stdoutBuffer.WriteByte(sep)
}

// Basic functions.

func unique(p *[]int) {
	a := *p
	n := len(a)
	if n > 0 {
		sort.Ints(a)
		i, j := 1, 0
		for ; i < n; i++ {
			if a[i] != a[j] {
				j++
				a[j] = a[i]
			}
		}
		*p = a[:j+1]
	}
}

// Splay tree.

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = getInt()
	m := getInt()
	a := make([]int, n)
	for i := range a {
		a[i] = getInt()
	}
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = getInt(), getInt()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	stdoutBuffer.Flush()
}

package main

import (
	"bufio"
	"bytes"
	"os"
	"sort"
	"strconv"
	"strings"
)

var (
	stdinBuffer  = bufio.NewReader(os.Stdin)
	stdoutBuffer = bufio.NewWriter(os.Stdout)
)

// Gets

func getWord() string {
	var (
		buf bytes.Buffer
		ch  byte
	)
	for ch == 0 || ch == ' ' || ch == '\n' {
		ch, _ = stdinBuffer.ReadByte()
	}
	for ch != 0 && ch != ' ' && ch != '\n' {
		buf.WriteByte(ch)
		ch, _ = stdinBuffer.ReadByte()
	}
	return buf.String()
}

func getInt() (ret int) {
	ret, _ = strconv.Atoi(getWord())
	return
}

func getIntSlice() []int {
	line, _ := stdinBuffer.ReadString('\n')
	tmp := strings.Fields(line)
	ret := make([]int, len(tmp))
	for i := range ret {
		ret[i], _ = strconv.Atoi(tmp[i])
	}
	return ret
}

// Puts

func putInt(v int, sep byte) {
	stdoutBuffer.WriteString(strconv.Itoa(v))
	stdoutBuffer.WriteByte(sep)
}

// End of the default code.

const MAX_N = 200005

var n int
var f = make([]int, MAX_N)
var p = make([]int, MAX_N)
var vec = make([][]int, MAX_N)

func add(i, x int) {
	for ; i <= n; i += i & -i {
		f[i] += x
	}
}

func sum(i int) (x int) {
	for ; i > 0; i -= i & -i {
		x += f[i]
	}
	return
}

func push(x, y int) {
	x, y = p[x], p[y]
	if x > y {
		x, y = y, x
	}
	vec[x] = append(vec[x], y)
	add(y, 1)
}

type Query struct {
	l, r, id int
}

type QueryArr []Query

func (q QueryArr) Len() int {
	return len(q)
}

func (q QueryArr) Swap(i, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q QueryArr) Less(i, j int) bool {
	return q[i].l < q[j].l
}

func main() {
	n = getInt()
	m := getInt()
	getIntSlice()
	a := getIntSlice()
	for i, v := range a {
		p[v] = i + 1
	}
	q := make(QueryArr, m)
	for i := range q {
		q[i].l, q[i].r = getInt(), getInt()
		q[i].id = i
	}
	sort.Sort(q)
	for i := 1; i <= n; i++ {
		for j := 1; j*i <= n; j++ {
			push(i, j*i)
		}
	}
	ans := make([]int, m)
	s := 1
	for _, q := range q {
		for ; s < q.l; s++ {
			for _, r := range vec[s] {
				add(r, -1)
			}
		}
		ans[q.id] = sum(q.r)
	}
	for _, v := range ans {
		putInt(v, '\n')
	}
	stdoutBuffer.Flush()
}


An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.

A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.

In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var (
	reader  = bufio.NewReader(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()

	if n == 1 || n == 2 {
		println(1)
		println(1)
		return
	}

	if n == 3 {
		println(2)
		println(1, 3)
		return
	}

	println(n)
	for i := n/2+1; i <= n; i++ {
		print(i, " ")
		if i != n || n%2 == 0{
			print(i-n/2, " ")
		}
	}
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
)

var scanner *bufio.Scanner
var writer *bufio.Writer

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := getI()
  if n <= 2 {
    writer.WriteString("1\n1\n")
    return
  }
  if n == 3 {
    writer.WriteString("2\n1 3\n")
    return
  }
  half := n/2 + 1
  writer.WriteString(fmt.Sprintf("%d\n%d", n, half))
  for i := 2; i <= n; i++ {
    x := i/2
    if i%2 == 1 {
      x += half
    }
    writer.WriteString(fmt.Sprintf(" %d", x))
  }
  writer.WriteString("\n")
}

package main

import "fmt"

func main() {
    n := 0
    fmt.Scanf("%d\n", &n)

    switch n {
    case 1:
        fmt.Println("1\n1")
    case 2:
        fmt.Println("1\n1")
    case 3:
        fmt.Println("2\n1 3")
    default:
        fmt.Println(n)
        for i := 2; i <= n; i += 2 {
            fmt.Printf("%d ", i)
        }
        for i := 1; i <= n; i += 2 {
            fmt.Printf("%d ", i)
        }
        fmt.Println("")
    }
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	switch {
	case n <= 2:
		fmt.Println("1")
		fmt.Println("1")
	case n == 3:
		fmt.Println("2")
		fmt.Println("1 3")
	default:
		fmt.Println(n)
		a := 2
		for i := 0; i < n; i++ {
			fmt.Print(a)
			if i != n - 1 {
				fmt.Print(" ")
			} else {
				fmt.Println("")
			}
			a += 2
			if a > n {
				a = 1
			}
		}
	}

}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	if n == 1 || n == 2 {
		fmt.Println("1")
		fmt.Println("1")
	} else if n == 3 {
		fmt.Println("2")
		fmt.Println("1 3")
	} else {
		fmt.Println(n)

		odd := n - 1
		even := n
		if n%2 != 0 {
			odd = n
			even = n - 1
		}
		for i := odd; i >= 1; i -= 2 {
			fmt.Printf("%d ", i)
		}
		for i := even; i >= 2; i -= 2 {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
	}
}

package main
import "fmt"
func main(){
    var n int
    fmt.Scanf("%d",&n)
    a := []int{}
    if n == 1 || n == 2 {
        fmt.Printf("%d\n%d\n",1,1)
    } else if n == 3 {
        fmt.Printf("2\n1 3\n")
    } else {
        f := false
        if n%2 == 0{
            n--
            f = true
        }
        for i := n ; i >=1 ;i-=2 {
            a = append(a,i)
        }
        if f {
            n++
        }
        if n % 2 == 1 {
            n--
        }
        for i:=n; i>=1; i-=2 {
            a = append(a,i)
        }
        fmt.Printf("%d\n",len(a))
        for i:=0; i<len(a);i++{
            fmt.Printf("%d ",a[i])
        }
        fmt.Printf("\n")
    }
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	switch n {
	case 1, 2:
		fmt.Printf("1\n1\n")
	case 3:
		fmt.Printf("2\n1 3\n")
	case 4:
		fmt.Printf("4\n3 1 4 2\n")
	default:
		fmt.Printf("%d\n", n)
		half := n / 2
		if n%2 != 0 {
			half++
		}
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				fmt.Printf("%d ", i/2+1)
			} else {
				fmt.Printf("%d ", (i-1)/2+half+1)
			}
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scanf("%v", &n)
    switch n {
    case 2:
        fmt.Print("1\n1")
    case 3:
        fmt.Print("2\n1 3")
    default:
        fmt.Printf("%v\n", n)
        for i := 2; i <= n; i += 2 {
            fmt.Printf("%v ", i)
        }
        for i := 1; i <= n; i += 2 {
            fmt.Printf("%v ", i)
        }
    }
    fmt.Println()
}

package main

import (
	"fmt"
)

func int_abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var n int
	fmt.Scan(&n)
	var ans []int
	var start1, start2 int
	if n%2 == 0 {
		start1 = n - 1
		start2 = n
	} else {
		start1 = n
		start2 = n - 1
	}
	for i := start1; i >= 1; i -= 2 {
		ans = append(ans, i)
	}
	if int_abs(start2-1) > 1 {
		ans = append(ans, start2)
	}
	for i := start2 - 2; i >= 1; i -= 2 {
		ans = append(ans, i)
	}
	fmt.Println(len(ans))
	for _, elem := range ans {
		fmt.Printf("%d ", elem)
	}
	fmt.Println("")
}

package main

import "fmt"

func main() {
	n := 0
	fmt.Scanf("%d\n", &n)

	switch n {
	case 1:
		fmt.Println("1\n1")
	case 2:
		fmt.Println("1\n1")
	case 3:
		fmt.Println("2\n1 3")
	default:
		fmt.Println(n)
		for i := 1; i < n; i += 2 {
			fmt.Printf("%d %d ", i+1, i)
		}
		if n % 2 == 1 {
			fmt.Printf("%d\n", n)
		} else {
			fmt.Println("")
		}
	}
}

package main
import "fmt"
func main(){
    var n int
    fmt.Scanf("%d",&n)
    a := []int{}
    if n == 1 || n == 2 {
        fmt.Printf("%d\n%d\n",1,1)
    } else if n == 3 {
        fmt.Printf("2\n1 3\n")
    } else {
        for i := 1 ; i <= n ;i+=2 {
            a = append(a,i)
        }
        if n % 2 == 1 {
            n--
        }
        for i:=n; i>=1; i-=2 {
            a = append(a,i)
        }
        fmt.Printf("%d\n",len(a))
        for i:=0; i<len(a);i++{
            fmt.Printf("%d ",a[i])
        }
        fmt.Printf("\n")
    }
}

package main
import "fmt"
func main(){
    var n int
    fmt.Scanf("%d",&n)
    a := []int{}
    if n == 1 || n == 2 {
        fmt.Printf("%d\n%d\n",1,1)
    } else if n == 3 {
        fmt.Printf("2\n1 3\n")
    } else {
        if n%2 == 0{
            n--
        }
        for i := n ; i >=1 ;i-=2 {
            a = append(a,i)
        }
        if n % 2 == 1 {
            n++
        }
        if n % 2 == 1 {
            n--
        }
        for i:=n; i>=1; i-=2 {
            a = append(a,i)
        }
        fmt.Printf("%d\n",len(a))
        for i:=0; i<len(a);i++{
            fmt.Printf("%d ",a[i])
        }
        fmt.Printf("\n")
    }
}