You are given an array $a_1, a_2, \dots, a_n$ consisting of $n$ distinct integers. Count the number of pairs of indices $(i, j)$ such that $i < j$ and $a_i \cdot a_j = i + j$.


-----Input-----

The first line contains one integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. Then $t$ cases follow.

The first line of each test case contains one integer $n$ ($2 \leq n \leq 10^5$) — the length of array $a$.

The second line of each test case contains $n$ space separated integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 2 \cdot n$) — the array $a$. It is guaranteed that all elements are distinct.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.


-----Output-----

For each test case, output the number of pairs of indices $(i, j)$ such that $i < j$ and $a_i \cdot a_j = i + j$.


-----Examples-----

Input
3
2
3 1
3
6 1 5
5
3 1 5 9 2
Output
1
1
3


-----Note-----

For the first test case, the only pair that satisfies the constraints is $(1, 2)$, as $a_1 \cdot a_2 = 1 + 2 = 3$

For the second test case, the only pair that satisfies the constraints is $(2, 3)$.

For the third test case, the pairs that satisfy the constraints are $(1, 2)$, $(1, 5)$, and $(2, 3)$.

Source: codeforces | Difficulty: EASY
Tags: Mathematics

Number theory

Implementation

Complete search


Solutions:
for y in range(int(input())):
	len_set = int(input())
	set_numbers = [int(x) for x in input().split()]
	k = 0
	for i in range(len_set):
		for j in range(set_numbers[i] - i - 2, len_set, set_numbers[i]):
			if i + j + 2 == set_numbers[i] * set_numbers[j] and i < j:
				k += 1
	print(k)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections, string, bisect, re, random, queue, itertools, statistics, math
from collections import *
from bisect import *
from string import *
from itertools import *
from statistics import *
from math import *
from re import *
from queue import *

class Stack:

	def __init__(self):
		self.items = []

	def push(self, item):
		self.items.append(item)

	def pop(self):
		return self.items.pop()

	def empty(self):
		return self.items == []

	def size(self):
		return len(self.items)

	def at(self, idx):
		try:
			return self.items[idx]
		except:
			return -1

class priority_queue(object):

	def __init__(self):
		self.queue = []

	def __str__(self):
		return ' '.join([str(i) for i in self.queue])

	def empty(self):
		return len(self.queue) == 0

	def push(self, data):
		self.queue.append(data)

	def pop(self):
		try:
			max = 0
			for i in range(len(self.queue)):
				if self.queue[i] > self.queue[max]:
					max = i
			item = self.queue[max]
			del self.queue[max]
			return item
		except IndexError:
			print()
			exit()
mod = int(1000000000.0 + 7)
imax = float('inf')
imin = float('-inf')
true = True
false = False
N = int(100000.0)
none = None
inp = lambda : input()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
MS = lambda : map(str, inp().split())
S = lambda : list(MS())
L = lambda : list(M())

def IO():
	try:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('uttar.txt', 'w')
	except:
		pass
IO()

class helper:

	def first(self, arr):
		return arr[0]

	def second(self, arr):
		return arr[1]

def kabraji_ka_totka():
	n = I()
	arr = L()
	res = 0
	for i in range(1, n):
		for j in range(arr[i - 1] - i % arr[i - 1], n + 1, arr[i - 1]):
			if i >= j:
				continue
			if i + j == arr[i - 1] * arr[j - 1]:
				res += 1
	print(res)
for i in range(I()):
	kabraji_ka_totka()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	d = dict()
	lal = dict()
	c = 0
	for (i, j) in enumerate(a):
		d[j] = i + 1
		lal[j] = True
	for i in range(1, int((2 * n) ** 0.5) + 1):
		if lal.get(i, False):
			start = i + 1
			while start * i <= 2 * n:
				if start == i:
					start += 1
					continue
				if lal.get(start, False):
					if d[start] + d[i] == i * start:
						c += 1
				start += 1
	print(c)


from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	cnt = 0
	m = defaultdict(list)
	for (i, x) in enumerate(a):
		y = 1
		while y * x < 2 * (i + 1):
			if y in m and y * x - i - 1 in m[y]:
				cnt += 1
			y += 1
		m[x].append(i + 1)
	print(cnt)


t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	c = 0
	for i in range(1, n):
		tog = 2 * (i + 1)
		if tog / arr[i] <= 1:
			continue
		m = tog % arr[i]
		pos = i
		if m != 0:
			if i - m < 0:
				break
			n1 = (tog - m) // arr[i]
			n2 = arr[i - m]
			if n1 == n2:
				c += 1
			tog -= m
			pos = i - m
		while tog > arr[i]:
			tog -= arr[i]
			pos -= arr[i]
			if pos < 0:
				break
			if tog // arr[i] == arr[pos]:
				c += 1
	print(c)


from functools import *
from math import *
from sys import *
from itertools import *

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.insert(0, -1)
	ans = 0
	for i in range(1, n + 1, 1):
		for j in range(a[i] - i, n + 1, a[i]):
			if a[i] * a[j] == i + j and i < j:
				ans += 1
	print(ans)
t = int(input())
for case in range(t):
	solve()


def f(A):
	x = 0
	for i in range(n):
		for j in range(A[i] - 2 - i, n, A[i]):
			if i < j:
				if i + j + 2 == A[i] * A[j]:
					x = x + 1
	return x
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(f(l))


import sys
import math
from collections import deque
I = sys.stdin.readline
IN = lambda x: map(int, x.split())
L = lambda x: list(IN(x))
for _ in range(int(I())):
	n = int(I())
	a = L(I())
	c = 0
	d = {}
	mx = 4 * n - 1
	for i in range(n):
		d[a[i]] = i + 1
	for i in range(1, 2 * n + 1):
		k = d.get(i)
		if k is None:
			continue
		for j in range(i + 1, 2 * n + 1):
			temp = i * j
			if temp > mx:
				break
			j1 = d.get(j)
			if j1 is None:
				continue
			if temp == k + j1:
				c += 1
	print(c)


for h in range(int(input())):
	r = int(input())
	u = list(map(int, input().split()))
	res = 0
	for i in range(r):
		for j in range(u[i] - i - 2, r, u[i]):
			if i + j + 2 == u[i] * u[j] and i < j:
				res += 1
	print(res)


def pair(a):
	ans = 0
	dd = {}
	for (i, n) in enumerate(a):
		i = i + 1
		m = 1
		while m * n <= 2 * i - 1:
			if m in dd and dd[m] + i == m * n:
				ans += 1
			m += 1
		dd[n] = i
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	s = input()
	a = [int(a) for a in s.split(' ')]
	print(pair(a))


import math

def main_function():
	tests = range(int(input()))
	for test in tests:
		n = int(input())
		a = [int(i) for i in input().split(' ')]
		b = []
		a_greater_ind = []
		ind_greater_a = []
		counter = 0
		for i in range(len(a)):
			ind = i + 1
			b.append((a[i], ind))
		b.sort(key=lambda x: x[0])
		for i in range(len(b)):
			(a_i, ind_i) = b[i]
			for j in range(i + 1, len(b)):
				(a_j, ind_j) = b[j]
				if a_j * a_i > 2 * n:
					break
				if a_i * a_j == ind_i + ind_j:
					counter += 1
		print(counter)
main_function()


from sys import stdin, stdout
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
from math import ceil, gcd, sqrt, factorial, log2, floor
import heapq
for _ in range(it()):
	n = it()
	l = mp()
	l = sorted(list(enumerate(l, 1)), key=lambda x: x[1])
	ans = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			if l[i][1] * l[j][1] == l[i][0] + l[j][0]:
				ans += 1
			elif l[i][1] * l[j][1] > 2 * n - 1:
				break
	print(ans)


for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	r = i = 0
	for x in a:
		i += 1
		for j in range(-i % x or x, i, x):
			r += x * a[j - 1] == i + j
	print(r)


def main(r):
	return r

def fun(a):
	while a > 0:
		a -= 1
		ar = [0]
		n = int(input())
		l = list(map(int, input().split()))
		for i in l:
			ar.append(i)
		c = 0
		for i in range(1, n + 1):
			j = ar[i]
			j -= i % ar[i]
			while j <= n:
				if i != j and i + j == ar[i] * ar[j]:
					c += 1
				j += ar[i]
		print(main(c // 2))
a = int(input())
fun(a)


import math as mt
from collections import defaultdict as df
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = df(int)
	b = []
	c = []
	for i in range(n):
		b.append([a[i], i + 1])
		c.append(b[i])
	c.sort()
	i = 0
	j = 1
	cnt = 0
	res = True
	for i in range(n):
		for j in range(n):
			if b[i][0] * c[j][0] > 2 * n:
				break
			elif b[i][0] * c[j][0] == b[i][1] + c[j][1] and b[i][1] < c[j][1]:
				cnt += 1
	print(cnt)


import math
for _ in range(int(input())):
	n = int(input())
	l = [10 ** 6 for i in range(2 * n + 1)]
	l1 = list(map(int, input().split()))
	for i in range(n):
		l[l1[i]] = i + 1
	count = 0
	for i in range(3, 2 * n):
		for j in range(1, int(math.sqrt(i)) + 1):
			if i % j == 0 and i != j * j:
				if l[j] + l[int(i / j)] == i:
					count = count + 1
	print(count)


def rez():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	arr.insert(0, 0)
	for i in range(1, n + 1):
		for j in range(arr[i] - i, n + 1, arr[i]):
			if j > 0 and i < j:
				if arr[i] * arr[j] == i + j:
					ans += 1
	print(ans)
for t in range(int(input())):
	rez()


T = int(input())
for k in range(T):
	n = int(input())
	a = [0]
	a.extend(map(int, input().split()))
	ans = 0
	for i in range(1, n + 1):
		st = ((a[i] - i) % a[i] + a[i]) % a[i]
		for j in range(st, i, a[i]):
			if i + j == a[i] * a[j]:
				ans += 1
	print(ans)


from math import ceil
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	c = 0
	for i in range(1, n + 1):
		start = arr[i - 1] * ceil(i / arr[i - 1])
		for j in range(start, 2 * i, arr[i - 1]):
			if j - i - 1 >= 0 and arr[j - i - 1] == j / arr[i - 1]:
				c += 1
	print(c)


def getPairs(arr, n):
	ans = 0
	for i in range(1, n + 1):
		temp = arr[i] - i
		while temp <= n:
			if temp <= i:
				temp += arr[i]
				continue
			if arr[i] * arr[temp] == i + temp:
				ans += 1
			temp += arr[i]
	return ans
N = int(input())
for i in range(N):
	n = int(input())
	arr = [0] + list(map(int, input().rstrip().split()))
	print(getPairs(arr, n))


for _ in range(int(input())):
	(n, c, a) = (int(input()), 0, [0] + list(map(int, input().split())))
	for i in range(1, n):
		b = a[i]
		for j in range(i - 2 * i % b + b, n + 1, b):
			c += b * a[j] == i + j
	print(c)


t = int(input())
for q in range(t):
	answ = 0
	n = int(input())
	a = [int(i) for i in input().split()]
	for i in range(1, n + 1):
		ai = a[i - 1]
		j = ai - i % ai + i // ai * ai
		while j <= i:
			j += ai
		for k in range(j, n + 1, ai):
			if a[k - 1] * a[i - 1] == k + i:
				answ += 1
	print(answ)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = 0
	idx = {}
	for a in range(n):
		idx[arr[a]] = a + 1
	arr.sort()
	for j in range(n):
		k = 1
		while k + j < n and arr[j] * arr[k + j] <= 2 * n:
			if arr[j] * arr[k + j] == idx[arr[j]] + idx[arr[k + j]]:
				ans += 1
			k += 1
	print(ans)


def main():
	n = int(input())
	for i in range(n):
		t = int(input())
		a = list(map(int, input().split()))
		c = 0
		for i in range(1, t + 1):
			for j in range(a[i - 1] - i, t + 1, a[i - 1]):
				if a[i - 1] * a[j - 1] == i + j and i < j:
					c += 1
		print(c)
main()


for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	count = 0
	for i in range(n):
		for j in range(nums[i] - i - 2, n, nums[i]):
			if nums[i] * nums[j] == i + j + 2 and i < j:
				count += 1
	print(count)


import sys
getline = sys.stdin.readline

def read_int():
	return int(getline())

def read_ints():
	return list(map(int, getline().split()))
for _ in range(read_int()):
	n = read_int()
	a = read_ints()
	b = []
	for i in range(n):
		b.append((a[i], i + 1))
	b = sorted(b)
	ms = n + n - 1
	ans = 0
	for i in range(n):
		if b[i][0] > ms:
			break
		for j in range(i + 1, n):
			if b[i][0] * b[j][0] > ms:
				break
			ans += b[i][0] * b[j][0] == b[i][1] + b[j][1]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d1 = {}
	for i in range(0, n):
		d1[arr[i]] = i + 1
	count = 0
	for i in range(n):
		index1 = i + 1
		elem1 = arr[i]
		now = elem1 * 1
		while True:
			need_index = now - index1
			need_mnog = now // arr[i]
			need_real = need_index - 1
			if need_index >= index1:
				break
			if need_real >= 0 and arr[need_real] == need_mnog:
				count += 1
			now += elem1
	print(count)


from sys import stdin, stdout

def input():
	return stdin.readline().strip()

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

def read_int_tuple():
	return tuple(map(int, input().split()))

def read_int():
	return int(input())

def ans(lst):
	index = dict()
	for i in range(len(lst)):
		index[lst[i]] = i + 1
	sl = set(lst)
	target = 2 * max(lst)
	ret = 0

	def ok(ai, aj):
		if not (ai in sl and aj in sl):
			return False
		i = index[ai]
		j = index[aj]
		return i < j and i + j == ai * aj
	for ai in range(1, target + 10):
		for aj in range(ai + 1, target + 10):
			if ai * aj > target:
				break
			if ok(ai, aj):
				ret += 1
			if ok(aj, ai):
				ret += 1
	return ret
if True:
	for _ in range(read_int()):
		input()
		print(ans(read_int_list()))
else:
	N = 100000
	tc = list(range(1, N))
	print(ans(tc))


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(n - 1):
		b = 1
		while True:
			j = a[i] * b - (i + 2)
			if j < n:
				if i < j and a[j] == b:
					c += 1
			else:
				break
			b += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	b = [int(v) for v in input().split()]
	a = []
	for j in range(n):
		a.append([b[j], j])
	j = 0
	k = 1
	l = 2 * n - 1
	c = 0
	a.sort()
	for j in range(n - 1):
		k = j + 1
		while k < n:
			if a[j][0] * a[k][0] == a[j][1] + a[k][1] + 2:
				c = c + 1
			elif a[j][0] * a[k][0] > l:
				break
			k = k + 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	b.append(a[0])
	cnt = 0
	for i in range(1, len(a)):
		cur = a[i]
		for z in range(cur - (i + 1) % cur - 1, i + 1, cur):
			if z < len(b):
				if b[z] * cur == z + i + 2:
					cnt += 1
		b.append(cur)
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	count = 0
	a = [0] + list(map(int, input().split()))
	for j in range(1, n + 1):
		start = a[j] - j % a[j]
		for i in range(start, j, a[j]):
			if a[j] * a[i] == i + j:
				count += 1
	print(count)


import math

def lerp(val, lb, ub, lv, uv):
	return lv + (val - lb) * (uv - lv) / (ub - lb)

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

def get_floats():
	return list(map(float, input().split()))
for _ in range(int(input())):
	N = int(input())
	a = get_ints()
	count = 0
	for j in range(1, N):
		i = 0
		m = 1
		while 1:
			i = m * a[j] - j - 2
			if i >= j:
				break
			if i < 0:
				m += 1
				continue
			if m == a[i]:
				count += 1
			m += 1
	print(count)


for _ in range(int(input())):
	x = int(input())
	l = list(map(int, input().split()))
	c = 0
	for i in range(len(l)):
		for j in range(l[i] - i - 2, len(l), l[i]):
			if l[i] * l[j] == i + 1 + j + 1 and i < j:
				c = c + 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	dp = [-1] * (2 * n + 1)
	for i in range(n):
		dp[l[i]] = i + 1
	ans = 0
	for i in range(n):
		for j in range(1, (2 * n - 1) // l[i] + 1):
			if i + 1 + dp[j] == l[i] * j and i + 1 != dp[j] and (dp[j] != -1):
				ans += 1
	print(ans // 2)


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	a = []
	for i in range(n):
		a.append((i + 1, arr[i]))
	a.sort(key=lambda x: x[1])
	count = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			if a[i][1] * a[j][1] > 2 * n:
				break
			if a[i][1] * a[j][1] == a[i][0] + a[j][0]:
				count += 1
	print(count)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
a = int(input())
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	cnt = 0
	for i in range(len(z)):
		val = z[i]
		rem = (i + 1) % val
		req = val - rem
		if req <= rem:
			req += val
		if req > rem:
			index = i + req - rem
		while index < len(z):
			if z[index] * val == index + 1 + i + 1:
				cnt += 1
			index += val
	print(cnt)


T = int(input())
frange = range
fprint = print
fint = int
fmap = map
finput = input
for i in frange(T):
	n = fint(finput())
	arr = list(fmap(fint, finput().split()))
	ans = 0
	arr = [0] + arr
	for i in frange(1, n + 1):
		for j in frange(arr[i] - i, n + 1, arr[i]):
			if j >= 0:
				if arr[i] * arr[j] == i + j and i < j:
					ans += 1
	fprint(ans)


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	loc = {a: i for (i, a) in enumerate(arr, 1)}
	res = 0
	for (i, a) in enumerate(arr, 1):
		for b in range(1, 2 * n // a + 1):
			if b in loc and a * b == i + loc[b] and (a != b):
				res += 1
	return res // 2
for _ in range(int(input())):
	print(solve())


t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	dic = dict()
	for i in range(n):
		dic[arr[i]] = i + 1
	arr.sort()
	ans = 0
	for i in range(n):
		if arr[i] >= 2 * n:
			break
		for j in range(i + 1, n):
			if arr[i] * arr[j] >= 2 * n:
				break
			ans += int(arr[i] * arr[j] == dic[arr[i]] + dic[arr[j]])
	print(ans)


for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	print(sum((i + j + 2 == x * a[j] for (i, x) in enumerate(a) for j in range(-(i + 2) % x, i, x))))


for _ in range(int(input())):
	n = int(input())
	a = [10 ** 18] + list(map(int, input().split()))
	ans = 0
	for j in range(n, 0, -1):
		ma = j + j - 1
		for i_plus_j in range(ma - ma % a[j], j, -a[j]):
			if a[i_plus_j - j] == i_plus_j // a[j]:
				ans += 1
	print(ans)


def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)

def fact(n):
	return 1 if n == 1 or n == 0 else n * fact(n - 1)

def prime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def inp():
	l = list(map(int, input().split()))
	return l
from collections import defaultdict
for _ in range(int(input())):
	(n,) = inp()
	a = inp()
	s = 0
	d = defaultdict(int)
	for i in range(n):
		d[a[i]] = i + 1
	a.sort()
	for i in range(n):
		for j in range(i + 1, n):
			if a[i] * a[j] == d[a[i]] + d[a[j]]:
				s += 1
			if a[i] * a[j] >= 2 * n - 1:
				break
	print(s)

def random():
	rating = 100
	rating = rating * 100
	rating = rating * 100
	print(rating)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ind = list(range(len(l)))
	zipped = zip(l, ind)
	zipped = sorted(zipped, key=lambda tup: tup[0])
	l = [x[0] for x in zipped]
	ind = [x[1] + 1 for x in zipped]
	ans = 0
	for i in range(len(l)):
		for j in range(i + 1, len(l)):
			if l[i] * l[j] > 2 * n:
				break
			if ind[i] + ind[j] == l[i] * l[j]:
				ans += 1
	print(ans)


import sys
import math
stdin = sys.stdin
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
t = ni()

def main():
	count = 0
	n = ni()
	A = na()
	for i in reversed(range(n)):
		for (j, J) in enumerate(range(A[i], 2 * n, A[i])):
			if J - i - 2 < i and J - i - 2 >= 0:
				if A[J - i - 2] == j + 1:
					count += 1
	print(count)
for _ in range(t):
	main()


for k in range(int(input())):
	count = 0
	n = int(input())
	a = list(map(int, input().split()))
	a.insert(0, 0)
	for i in range(1, len(a) - 1):
		v = a[i]
		j = a[i] - i
		while j <= i:
			j += v
		for j in range(j, len(a), v):
			if a[i] * a[j] == i + j:
				count += 1
	print(count)


def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		c = 0
		for i in range(n):
			ans = a[i] - (i + 2)
			if a[i] - (i + 1) <= i:
				while ans <= i:
					ans += a[i]
			if ans < n:
				for j in range(ans, n, a[i]):
					if j != i:
						if a[i] * a[j] == i + j + 2:
							c += 1
		print(c)
main()


t = int(input())
for i in range(t):
	c = 0
	n = int(input())
	l = list(map(int, input().split(' ')))
	for j in range(n):
		for k in range(l[j], 2 * n + 1, l[j]):
			a = k - j - 2
			if a >= 0 and a < j and (l[a] * l[j] == a + j + 2):
				c += 1
	print(c)


for k in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.insert(0, 0)
	cnt = 0
	for i in range(1, n + 1):
		now = a[i] - i
		for j in range(now, n + 1, a[i]):
			if i < j and i + j == a[i] * a[j]:
				cnt += 1
	print(cnt)


from math import sqrt
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	total = 0
	r = [2 * n + 100 for _ in range(2 * n + 1)]
	for i in range(len(a)):
		r[a[i]] = i + 1
	for i in range(1, 2 * n):
		for j in range(1, i):
			if i * j > 2 * n:
				break
			if r[j] + r[i] == i * j:
				total += 1
	print(total)


import math

def Solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.insert(0, 0)
	count = 0
	i = 1
	while i <= n - 1:
		k1 = i % a[i]
		k2 = a[i] - k1
		while k2 <= i:
			k2 += a[i]
		j = k2
		while j <= n:
			if i + j == a[i] * a[j]:
				count += 1
			j += a[i]
		i += 1
	print(count)
q = int(input())
while q > 0:
	Solve()
	q -= 1


from sys import path_hooks, stdin, stdout
from collections import Counter, deque
import math
from copy import deepcopy
import random
import heapq
from itertools import permutations, product, repeat
from time import time
from bisect import bisect_left
from bisect import bisect_right
from re import A, findall
from fractions import Fraction
from typing import DefaultDict

def mapinput():
	return map(int, stdin.readline().split())

def strinput():
	return stdin.readline().strip()

def listinput():
	return list(map(int, stdin.readline().split()))

def intinput():
	return int(stdin.readline().strip())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	ans = []
	for p in range(n + 1):
		if prime[p]:
			ans.append(p)
	return ans
spprime = [2, 3, 5, 7, 23, 29, 31, 37, 53, 59, 71, 73, 79, 233, 239, 293, 311, 313, 317, 373, 379, 593, 599, 719, 733, 739, 797, 2333, 2339, 2393, 2399, 2939, 3119, 3137, 3733, 3739, 3793, 3797, 5939, 7193, 7331, 7333, 7393, 23333, 23339, 23399, 23993, 29399, 31193, 31379, 37337, 37339, 37397, 59393, 59399, 71933, 73331, 73939, 233993, 239933, 293999, 373379, 373393, 593933, 593993, 719333, 739391, 739393, 739397, 739399, 2339933, 2399333, 2939999, 3733799]
spprimeset = set(spprime)
coprime1 = {6: 100003, 5: 10007, 4: 1009, 3: 101, 2: 11, 1: 2, 7: 1000003, 8: 10000019, 9: 100000007}
coprime2 = {8: 10000169, 9: 100000049, 7: 1000033, 6: 100019, 5: 10009, 4: 1013, 3: 103, 2: 13, 1: 3}

def writ(ss):
	stdout.write(str(ss) + '\n')
mod = 10 ** 9 + 7

def binaryr(arr, point, target):
	low = 0
	high = point
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] == target:
			return mid
		elif arr[mid] < target:
			low = mid + 1
		else:
			high = mid - 1
	return low

def binaryl(arr, point, target):
	low = 0
	high = point
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] == target:
			return mid
		elif arr[mid] < target:
			low = mid + 1
		else:
			high = mid - 1
	return high

def sump(n):
	return n * (n + 1) // 2
for test in range(intinput()):

	def solve():
		n = intinput()
		arr = listinput()
		d = {}
		for i in range(n):
			d[arr[i]] = i + 1
		arr.sort()
		ans = 0
		for i in range(n):
			e = arr[i]
			for j in range(i + 1, n):
				if e * arr[j] == d[e] + d[arr[j]]:
					ans += 1
				if e * arr[j] > 2 * n:
					break
		print(ans)
	solve()


for _ in range(int(input())):
	n = int(input())
	array = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		k = array[i]
		temp_i = k - i - 1
		while temp_i <= n:
			if array[temp_i - 1] == k // array[i] and temp_i > i + 1:
				ans += 1
			k += array[i]
			temp_i = k - i - 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = 3
	count = 0
	for i in range(n):
		for j in range(a[i] - i - 2, n, a[i]):
			if i >= j:
				continue
			if a[i] * a[j] == i + j + 2:
				count += 1
	print(count)


def sol(A):
	count = 0
	dic = {}
	dic[A[0]] = 0
	for i in range(1, len(A)):
		m = (2 * i + 1) // A[i]
		for ai in range(1, m + 1):
			if i + 2 <= ai * A[i] < 2 * i + 2 and ai in dic and (ai * A[i] == dic[ai] + 1 + (i + 1)):
				count += 1
		dic[A[i]] = i
	return count
x = int(input())
for _ in range(x):
	y = int(input())
	A = list(map(int, input().split()))
	print(sol(A))


T = int(input())
for case in range(0, T):
	n = int(input())
	a = [0]
	s = input().split()
	for i in range(0, n):
		a.append(int(s[i]))
	ans = 0
	for i in range(1, n + 1):
		for j in range(a[i] - i % a[i], n + 1, a[i]):
			if j >= i:
				pass
			elif a[i] * a[j] == i + j:
				ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	for i in range(n):
		for j in range(a[i] - i - 2, n, a[i]):
			if j > i and a[i] * a[j] == i + j + 2:
				cnt += 1
	print(cnt)


def f(ar):
	n = len(ar)
	ar = [0] + ar
	cnt = 0
	for i in range(1, len(ar)):
		fac = ar[i]
		j = ar[i] - i
		while fac - i <= n:
			if j < i and j >= 1 and (j <= n) and (ar[i] * ar[j] == i + j):
				cnt += 1
			fac += ar[i]
			j = fac - i
	return cnt
for i in range(int(input())):
	a = input()
	lst = list(map(int, input().strip().split()))
	print(f(lst))


def solve():
	ans = 0
	for i in range(N):
		a = A[i]
		max_b = min(a, (N + i + 1) // a + 1)
		for b in range(max_b, 0, -1):
			p = a * b
			j = p - i - 2
			if 0 <= j < N and i != j and (A[j] * A[i] == p):
				ans += 1
	return ans
test_cases = int(input())
for test_case in range(test_cases):
	N = int(input())
	A = list(map(int, input().split()))
	print(solve())


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(len([j for j in range(n) for k in range(a[j] - j - 2, n, a[j]) if a[j] * a[k] == j + k + 2 and j < k]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	arr = []
	ans = 0
	for i in range(n):
		arr.append([a[i], i + 1])
	arr = sorted(arr)
	for i in range(1, n):
		for j in range(i):
			if arr[i][0] * arr[j][0] > 2 * n:
				break
			elif arr[i][0] * arr[j][0] == arr[i][1] + arr[j][1]:
				ans += 1
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		total = 0
		n = int(input())
		a = [int(x) for x in input().split()]
		a = [(a[i], i + 1) for i in range(n)]
		a.sort(key=lambda x: x[0])
		for i in range(n):
			for j in range(n):
				if a[i][0] * a[j][0] > 2 * n:
					break
				elif i != j:
					if a[i][0] * a[j][0] == a[i][1] + a[j][1]:
						total += 1
		print(total // 2)
main()


for _ in ' ' * int(input()):
	n = int(input())
	result = 0
	arr = list(map(int, input().split()))
	for i in range(n):
		for j in range(arr[i] - i - 2, n, arr[i]):
			if j > i and arr[j] * arr[i] == i + j + 2:
				result += 1
	print(result)


def func1(a, n):
	counter = 0
	for i in range(n):
		for j in range(a[i] - i - 2, n, a[i]):
			if a[j] * a[i] == j + i + 2 and j > i:
				counter += 1
	print(counter)

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		func1(a, n)
main()


t = int(input())

def howm(n, L):
	res = 0
	for i in range(n):
		x = L[i]
		for y in range(x, 2 * n + 1, x):
			j = y - i - 2
			if j >= 0 and j < n and (j > i) and (L[j] * L[i] == i + j + 2):
				res += 1
	return res
for _ in range(t):
	n = int(input())
	L = [int(x) for x in input().split()]
	print(howm(n, L))


import sys

def main():
	t = Iint()
	for _ in range(t):
		n = Iint()
		a = Ilist()
		count = 0
		for (i, ai) in en(a):
			i = i + 1
			start = i + (ai - 2 * i % ai)
			jump = ai
			end = n + 1
			if start > n:
				continue
			for j in range(start, end, jump):
				if (i + j) // ai == a[j - 1]:
					count += 1
		print(count)
FIO = 10

def debug(*args, c=6):
	starter = '\x1b[3{}m'.format(c)
	ender = '\x1b[0m'
	if c == 0:
		(starter, ender) = ('', '')
	print(starter, *args, ender, file=sys.stderr, sep=' ')
BUFSIZE = 8 * 1024
en = enumerate
inf = float('inf')

def Istr():
	return input()

def Iint():
	return int(input())

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

def Imap():
	return map(int, input().split())

def Plist(li, s=' '):
	print(s.join(map(str, li)))
if not FIO:
	if __name__ == '__main__':
		main()
		exit()
else:
	from io import BytesIO, IOBase
	import os

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	occs = [-1] * (2 * n + 1)
	for i in range(n):
		occs[a[i]] = i + 1
	ans = 0
	for i in range(n):
		for j in range(a[i], 2 * n + 1, a[i]):
			if occs[j // a[i]] > i + 1:
				if j == i + 1 + occs[j // a[i]]:
					ans += 1
	print(ans)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	c = dict(Counter(l))
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieveForSmallestPrimeFactor():
	MAXN = 100001
	spf = [0 for i in range(MAXN)]
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, math.ceil(math.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
	return spf

def getPrimeFactorizationLOGN(x):
	spf = sieveForSmallestPrimeFactor()
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def si():
	return input()

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def solve():
	n = ii()
	l = [0] + li()
	d = defaultdict(lambda : 0)
	for i in range(1, n + 1):
		d[l[i]] = i
	ans = 0
	for i in range(1, 2 * n + 1):
		for j in range(1, i + 1):
			if j * j >= i:
				break
			if i % j == 0:
				mul = d[j]
				if mul != 0 and d[i // j] != 0:
					if mul + d[i // j] == i:
						ans += 1
	print(ans)
t = 1
t = ii()
for _ in range(t):
	solve()


for k in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	answer = 0
	for (i, t) in enumerate(a, 2):
		for j in range(-i % t, i - 2, t):
			if i + j == t * a[j]:
				answer += 1
	print(answer)


for _ in range(int(input())):
	(n, arr) = (int(input()), [None] + list(map(int, input().split())))
	ans = 0
	for i in range(1, n + 1):
		m = arr[i] * (i // arr[i] + 1)
		while m <= n + i:
			ans += arr[m - i] == m // arr[i] and i << 1 != m
			m += arr[i]
	print(ans >> 1)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(len(a)):
		x = 0
		while True:
			j = a[i] * x - 2 - i
			if j <= i:
				x += 1
			elif j >= len(a):
				break
			else:
				if a[j] == x:
					ans += 1
				x += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	mat = []
	for i in range(len(l)):
		mat.append([l[i], i + 1])
	mat.sort()
	c = 0
	for i in range(len(mat)):
		for j in range(i + 1, n):
			if mat[i][0] * mat[j][0] > 2 * n:
				break
			if mat[i][0] * mat[j][0] == mat[i][1] + mat[j][1]:
				c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().rstrip().split(' ')))
	ans = 0
	s = 2 * n - 1
	d = {}
	d_vis = {}
	for i in range(n):
		d[a[i]] = i + 1
		d_vis[a[i]] = False
	for i in range(n):
		for j in range(1, s // a[i] + 1):
			if j in d and j * a[i] == d[a[i]] + d[j] and (not d_vis[j]) and (j != a[i]):
				ans += 1
				d_vis[a[i]] = True
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	arr = [1000000] * (2 * n + 1)
	l = list(map(int, input().split()))
	for i in range(n):
		arr[l[i]] = i + 1
	ans = 0
	for i in range(3, 2 * n):
		for j in range(1, math.floor(math.sqrt(i) + 1)):
			if i % j == 0 and i != j * j:
				if arr[i // j] + arr[j] == i:
					ans += 1
	print(ans)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		arr = [(a[i], i + 1) for i in range(n)]
		arr.sort()
		cnt = 0
		L = 0
		R = n - 1
		while L < R:
			target = 2 * n / arr[L][0]
			(l, r) = (L, R)
			while l < r:
				m = l + (r - l) // 2
				if arr[m][0] > target:
					r = m
				else:
					l = m + 1
			R = l
			(ai, i) = arr[L]
			for k in range(L + 1, R + 1):
				(aj, j) = arr[k]
				if ai * aj == i + j:
					cnt += 1
			L += 1
		print(cnt)
while True:
	try:
		main()
	except:
		break


from collections import Counter
import math
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(input())
	x = list(map(int, stdin.readline().split(' ')))
	count = 0
	for i in range(1, n):
		a = x[i - 1]
		ind = -1
		if n + i >= a:
			if 2 * i + 1 <= a:
				ind = a
			elif 2 * i + 1 > a:
				b = (2 * i + 1) / a
				if b == int(b):
					ind = 2 * i + 1
				else:
					b = int(b)
					ind = a * (b + 1)
		if ind == -1:
			pass
		else:
			for j in range(ind, n + i + 1, a):
				if a * x[j - i - 1] == j:
					count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	for i in range(n):
		aj = 1
		while True:
			j = aj * a[i] - (i + 1)
			if j > n:
				break
			if j <= i + 1:
				aj += 1
				continue
			if a[j - 1] == aj:
				cnt += 1
			aj += 1
	print(cnt)


T = int(input())
for case in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	arr = [(arr[i], i + 1) for i in range(n)]
	arr.sort()
	outer = n
	for i in range(n - 1):
		j = i + 1
		while j < outer:
			if arr[i][0] * arr[j][0] > 2 * n:
				outer = j
				break
			elif arr[i][0] * arr[j][0] == arr[i][1] + arr[j][1]:
				ans += 1
			j += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	for i in range(0, n):
		for j in range(a[i] - i - 2, n, a[i]):
			if j >= 0 and j > i and (a[i] * a[j] == i + j + 2):
				count += 1
	print(count)


def fast3():
	import os, sys, atexit
	from io import BytesIO
	sys.stdout = BytesIO()
	_write = sys.stdout.write
	sys.stdout.write = lambda s: _write(s.encode())
	atexit.register(lambda : os.write(1, sys.stdout.getvalue()))
	return BytesIO(os.read(0, os.fstat(0).st_size)).readline
input = fast3()
for _ in range(int(input())):
	(n, a) = (int(input()), [int(x) for x in input().split()])
	(ans, mem) = (0, [0] * (2 * n + 1))
	for i in range(n):
		mem[a[i]] = i + 1
	for i in range(n):
		cur = 1
		while a[i] * cur <= n * 2:
			ans += cur != a[i] and mem[cur] and (cur * a[i] == mem[cur] + mem[a[i]])
			cur += 1
	print(ans >> 1)


from math import ceil
t = int(input())
for _ in range(t):
	n = int(input())
	lst = [0]
	lst.extend(list(map(int, input().split())))
	tot = 0
	for i in range(1, n + 1):
		num = lst[i]
		startMul = i * 2 // num + 1
		startInd = startMul * num - i
		while startInd <= n:
			if lst[startInd] == startMul:
				tot += 1
			startInd += num
			startMul += 1
	print(tot)


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		k = arr[i] - i - 1
		while k <= i + 1:
			k += arr[i]
		for j in range(k - 1, n, arr[i]):
			if arr[i] * arr[j] == i + j + 2:
				ans += 1
	print(ans)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if l[i] in d:
			d[l[i]][i] = 1
		else:
			d[l[i]] = {i: 1}
	v = list(range(1, 2 * n + 1))
	out = 0
	for i in range(n):
		for j in range(l[i], 2 * n + 1, l[i]):
			c = j // l[i]
			if c in d:
				if j - (i + 1) - 1 in d[c] and j - (i + 1) - 1 != i:
					out += 1
	print(out // 2)


t = int(input())
for x in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	c = 0
	for i in range(n):
		for j in range(a[i] - i - 2, n, a[i]):
			if i + j + 2 == a[i] * a[j] and i < j and (j > 0):
				c += 1
	print(c)


def multiples(x, y, a):
	z = x - y % x - 1 + y // x * x
	if z < y:
		z = z + x
	m = 0
	for i in range(z, len(a), x):
		if x * a[i] == y + i + 1:
			m += 1
	return m
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = 0
	for i in range(n - 1):
		t += multiples(a[i], i + 1, a)
	print(t)


import sys
input = sys.stdin.readline
tt = int(input())
for mmm in range(tt):
	ans = 0
	n = int(input())
	n = 2 * n - 1
	nums = list(map(int, input().split()))
	nums = [[nums[i], i + 1] for i in range(len(nums))]
	nums.sort(key=lambda x: x[0])
	for i in range(len(nums)):
		for j in range(i + 1, len(nums)):
			val = nums[i][0] * nums[j][0]
			if val > n:
				break
			if val == nums[i][1] + nums[j][1]:
				ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	d = {}
	for i in range(n):
		d[l[i]] = i + 1
	l.sort()
	count = 0
	for i in range(n):
		for j in range(i + 1, n):
			s = d[l[i]] + d[l[j]]
			p = l[i] * l[j]
			if p == s:
				count += 1
			if p > 2 * n - 1:
				break
	print(count)


def solve(n, a):
	a = [0] + a
	ans = 0
	for i in range(1, n + 1):
		for m in range(a[i], 200000, a[i]):
			j = m - i
			if j > n:
				break
			if j <= i:
				continue
			if a[i] * a[j] == i + j:
				ans += 1
	return ans
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	arr = [10000000.0] * (2 * n + 1)
	for i in range(n):
		arr[a[i]] = i + 1
	ct = 0
	for i in range(3, 2 * n):
		for j in range(1, int(i ** 0.5) + 1):
			if i % j == 0 and i != j ** 2:
				if arr[j] + arr[i // j] == i:
					ct += 1
	print(ct)


def func():
	count = 0
	for i in range(1, n + 1):
		for j in range(a[i] - i, n + 1, a[i]):
			if j < 0:
				continue
			if i + j == a[i] * a[j] and i < j:
				count += 1
	print(count)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.insert(0, -10 ** 7)
	func()


import math
for _ in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	val = [1e+18] * (2 * n + 1)
	for i in range(n):
		val[ai[i]] = i + 1
	ans = 0
	for i in range(3, 2 * n):
		for ii in range(1, int(i ** 0.5) + 1):
			if i % ii == 0 and i != ii * ii:
				if val[ii] + val[i // ii] == i:
					ans += 1
	print(ans)


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())
mod = 1000000007

def solve(n, a):
	arr = []
	for i in range(n):
		arr.append([a[i], i + 1])
	arr.sort()
	c = 0
	for i in range(n):
		for j in range(i + 1, n):
			val = arr[i][0] * arr[j][0]
			if val > 2 * n - 1:
				break
			if val == arr[i][1] + arr[j][1]:
				c += 1
	print(c)
for _ in range(int(input())):
	n = int(input())
	arr = int_arr()
	solve(n, arr)


def solve(n, a):
	count = dict()
	for (i, x) in enumerate(a):
		count[x] = 0
		(start, end) = ((i + 2) // x, (2 * i + 1) // x)
		for j in range(max(1, start), end + 1):
			tmp = j * x - i - 2
			if 0 <= tmp < len(a) and j == a[tmp]:
				count[a[tmp]] += 1
	return sum(count.values())
T = int(input())
for case in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	res = solve(N, A)
	print(res)


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(n):
		d[l[i]] = i + 1
	x = []
	for i in sorted(d.keys()):
		x.append(d[i])
	l.sort()
	c = 0
	for i in range(n):
		for j in range(i + 1, n):
			v1 = l[i] * l[j]
			v2 = x[i] + x[j]
			if v1 == v2:
				c += 1
			if v1 > 2 * n:
				break
	print(c)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		term = a[i]
		index = i + 1
		part1 = index % term
		part2 = term - part1
		if part2 <= part1:
			start = i + part2 * 2
		else:
			start = i + (part2 - part1)
		for j in range(start, n, term):
			if a[i] * a[j] == i + j + 2:
				ans += 1
	print(ans)
	t -= 1


import sys
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	ls.insert(0, 0)
	cnt = 0
	for i in range(1, n + 1):
		for j in range(ls[i] - i, n + 1, ls[i]):
			if i + j == ls[i] * ls[j] and j >= 0 and (i < j):
				cnt += 1
	print(cnt)


def soluciona():
	contador = 0
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(n):
		for k in range(a[j] - j - 2, n, a[j]):
			if a[j] * a[k] == j + k + 2 and j < k:
				contador += 1
	print(contador)
	pass
for _ in range(int(input())):
	soluciona()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	r = 0
	for i in range(1, n + 1):
		v = a[i - 1]
		for j in range(1, 4 * n):
			x = v * j - i
			if x > n:
				break
			if x > 0 and x != i and (a[x - 1] == j):
				r += 1
	print(r // 2)
for i in range(int(input())):
	solve()


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	a = [(a[i], i + 1) for i in range(n)]
	a.sort()
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			if a[i][0] * a[j][0] > 2 * n:
				break
			if a[i][0] * a[j][0] == a[i][1] + a[j][1]:
				ans += 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	arr = [[int(c), int(k)] for (k, c) in enumerate(input().split(), start=1)]
	count = 0
	maxi = 2 * n - 1
	arr.sort()
	for ele in range(n):
		for ele2 in range(ele + 1, n):
			val = arr[ele][0] * arr[ele2][0]
			if val > maxi:
				break
			if val == arr[ele][1] + arr[ele2][1]:
				count += 1
	print(count)


PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

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

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	n = ii()
	a = li()
	a.insert(0, 0)
	ans = 0
	for i in range(1, n + 1):
		x = a[i]
		ind = 1
		while ind * x - i <= n:
			y = ind * x - i
			if y >= 1 and y > i:
				if a[y] == ind:
					ans += 1
			ind += 1
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in range(n):
		b.append((a[i], i + 1))
	b.sort()
	an = 0
	for i in range(n):
		for j in range(i + 1, n):
			if b[i][0] * b[j][0] > b[i][1] + n:
				break
			if b[i][0] * b[j][0] == b[i][1] + b[j][1]:
				an += 1
	print(an)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	temp = []
	for i in range(2 * n + 1):
		temp.append(10000000)
	for i in range(n):
		temp[a[i]] = i + 1
	ans = 0
	for i in range(3, 2 * n):
		for j in range(1, int(sqrt(i)) + 1):
			if i % j == 0 and i != j ** 2:
				if temp[j] + temp[i // j] == i:
					ans += 1
	print(ans)


n = int(input())
for i in range(n):
	element_count = 0
	len_arr = int(input())
	array = list(map(int, input().strip().split()))
	for k in range(0, len_arr):
		for j in range(array[k] - k - 2, len_arr, array[k]):
			if array[k] * array[j] == k + j + 2 and k < j:
				element_count += 1
	print(element_count)


import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	di = {a[i]: i for i in range(n)}
	co = 0
	for i in range(n):
		fac = a[i]
		need = i + 1
		for j in range(fac, 2 * n + 1, fac):
			if j // fac in di and j // fac != fac:
				if need + di[j // fac] + 1 == j:
					co += 1
	print(co // 2)


def add_dic(dic, n, arr):
	for i in range(n):
		dic[arr[i]] = i + 1

def test(temp, arr, dic, j):
	return temp * arr == dic[temp] + dic[arr]
T = int(input())
for q in range(T):
	dic = {}
	n = int(input())
	arr = input().split()
	arr = list(map(int, arr))
	add_dic(dic, n, arr)
	fin = 0
	arr.sort()
	for i in range(n):
		temp = arr[i]
		for j in range(i + 1, n):
			if test(temp, arr[j], dic, j):
				fin += 1
			if n * 2 < temp * arr[j]:
				break
	print(fin)


for cases in range(int(input())):
	n = int(input())
	k = 0
	ls = list(map(int, input().split()))
	for i in range(n):
		for j in range(ls[i] - i - 2, n, ls[i]):
			if ls[i] * ls[j] == i + j + 2 and j > i:
				k += 1
	print(k)


def fac(n):
	l = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0 and n // i != i:
			l.append(i)
	return l
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = [False] * (n * 2 + 1)
	for i in range(n):
		l[a[i]] = i + 1
	ctr = 0
	for i in range(3, 2 * n):
		x = fac(i)
		for j in x:
			if l[j]:
				if l[i // j] and l[i // j] + l[j] == i:
					ctr += 1
	print(ctr)


def fun(n, st):
	count = 0
	pair = [[st[i], i + 1] for i in range(n)]
	pair = sorted(pair)
	for i in range(n):
		first = pair[i]
		for j in range(i + 1, n):
			second = pair[j]
			if first[0] * second[0] == first[1] + second[1]:
				count += 1
			if first[0] * second[0] > 2 * n:
				break
	print(count)
T = int(input())
for i in range(T):
	val = int(input())
	st = list(map(int, input().split()))
	fun(val, st)


t = int(input())
for i in range(t):
	n = int(input())
	a = [0] * (n + 1)
	a[1:] = list(map(int, input().split()))
	indices = [-10 ** 12] * (2 * n + 1)
	for j in range(1, n + 1):
		indices[a[j]] = j
	count = 0
	p = 1
	while p <= 2 * n:
		q = p
		while q <= 2 * n:
			actual = q // p
			if actual != p and indices[actual] + indices[p] == q:
				count = count + 1
			q = q + p
		p = p + 1
	print(count // 2)


T = int(input())
for _ in range(T):
	n = int(input())
	an = [int(e) for e in input().split()]
	an = [(an[i], i + 1) for i in range(len(an))]
	an.sort()
	ans = 0
	for i in range(0, len(an)):
		for j in range(i + 1, len(an)):
			mul = an[i][0] * an[j][0]
			if mul > 2 * n:
				break
			if mul == an[i][1] + an[j][1]:
				ans += 1
	print(ans)


list_ans = []
for _ in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	ans = 0
	for i in range(n - 1):
		x = list1[i]
		for j in range(((2 * i + 2) // x + 1) * x - i - 2, n, x):
			if x * list1[j] == i + j + 2:
				ans += 1
	list_ans.append(ans)
for item in list_ans:
	print(item)


import sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	ans = 0
	dic = {}
	for i in range(1, n + 1):
		dic[arr[i - 1]] = i
	arr.sort()
	for i in range(0, n - 1):
		for j in range(i + 1, n):
			if arr[i] * arr[j] == dic[arr[i]] + dic[arr[j]]:
				ans += 1
			if arr[i] * arr[j] >= 2 * n:
				break
	print(ans)


x = int(input())
while x > 0:
	n = int(input())
	a = [int(x) for x in input().split()]
	a.insert(0, 0)
	r = 0
	for i in range(2, n + 1):
		j = (i // a[i] + 1) * a[i] - i
		for k in range(j, i, a[i]):
			if a[i] * a[k] == i + k:
				r += 1
	print(r)
	x -= 1


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	for j in range(n):
		k = 1
		while a[j] * k - 2 - j < n:
			if a[a[j] * k - 2 - j] == k and a[j] * k - 2 - j > j:
				s += 1
			k += 1
	print(s)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	cnt = defaultdict(lambda : -1)
	ans = 0
	for i in range(n):
		low = i + 1 + 1
		high = 2 * i + 1
		newl = low // arr[i] + (0 if low % arr[i] == 0 else 1)
		newh = high // arr[i]
		for k in range(newl, newh + 1):
			if cnt[k] != -1:
				ans += cnt[k] + i + 1 == arr[i] * arr[cnt[k] - 1]
		cnt[arr[i]] = i + 1
	print(ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	req = ((2 * n) ** 0.5 + 10) * 10
	ans = 0
	l = []
	for i in range(n):
		l.append([arr[i], i])
	l.sort()
	for i in range(n):
		for j in range(i + 1, n):
			if l[i][0] * l[j][0] == l[i][1] + l[j][1] + 2:
				ans += 1
			elif l[i][0] * l[j][0] >= 2 * n:
				break
	print(ans)


for _ in range(int(input())):
	c = 0
	n = int(input())
	a = list(map(int, input().split()))
	for j in range(n):
		for k in range(a[j] - j - 2, n, a[j]):
			if a[j] * a[k] == j + k + 2 and j < k:
				c += 1
	print(c)


n = int(input())

def check():
	k = int(input())
	nums = list(map(int, input().split()))
	counter = 0
	for (_index, num) in enumerate(nums):
		index = _index + 1
		start = (2 * index - 1) // num * num - index
		while start > 0:
			if nums[start - 1] * num == start + index:
				counter += 1
			start -= num
	return counter
for i in range(n):
	print(check())


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	s = dict()
	for i in range(n):
		s[a[i]] = i + 1
	ans = 0
	for val1 in range(1, 2 * n + 1):
		if val1 in s:
			index1 = s[val1]
			for val2 in range(val1 + 1, 2 * n + 1):
				if val1 * val2 > 2 * n:
					break
				if val2 in s:
					index2 = s[val2]
					if val1 * val2 == index1 + index2:
						ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().strip().split()]
	d = {a[0]: 1}
	count = 0
	for i in range(1, n):
		min_p = i + 2
		max_p = 2 * (i + 1) - 1
		k = i // a[i]
		if k == 0:
			k = 1
		while a[i] * k <= max_p:
			temp = a[i] * k - (i + 1) - 1
			if a[temp] == k and temp < i and (temp >= 0):
				count += 1
			k += 1
	print(count)


import math
for t in [*open(0)][2::2]:
	a = [*map(int, t.split())]
	s = set(a)
	ans = 0
	for n in range(len(a)):
		i = n + 1
		flagx = max(math.ceil((i + i + 1) / a[n]), 1)
		nowAi = a[n] * flagx
		while True:
			j = nowAi - i
			if j <= 0 or j <= i:
				nowAi = nowAi + a[n]
				continue
			if j > len(a):
				break
			if (i + j) // a[i - 1] == a[j - 1]:
				ans = ans + 1
			nowAi = nowAi + a[n]
	print(ans)


import sys
import math
import random
from queue import PriorityQueue as PQ
from bisect import bisect_left as BSL
from bisect import bisect_right as BSR
from collections import OrderedDict as OD
from collections import Counter
from itertools import permutations
mod = 1000000007
sys.setrecursionlimit(1000000)
try:
	sys.stdin = open('actext.txt', 'r')
	OPENFILE = 1
except:
	pass

def get_ints():
	return map(int, input().split())

def palindrome(s):
	mid = len(s) // 2
	for i in range(mid):
		if s[i] != s[len(s) - i - 1]:
			return False
	return True

def check(i, n):
	if 0 <= i < n:
		return True
	else:
		return False

def solve(arr, n):
	counter = 0
	for (num, i) in enumerate(arr):
		num = num + 1
		val = 1
		j = 0
		while val <= n:
			val = i * j - num
			if 1 <= val <= n and arr[val - 1] == j and (val > num):
				counter += 1
			j += 1
	print(counter)
t = int(input())
for tt in range(t):
	n = int(input())
	arr = list(get_ints())
	solve(arr, n)


def solve(n, a):
	c = 0
	for i in range(n):
		k = 1
		while True:
			j = a[i] * k - (i + 1) - 1
			if j >= n:
				break
			if j >= 0 and i < j and (a[j] == k):
				c += 1
			k += 1
	return c
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(n, a))


import sys
import math
mod = 10 ** 9 + 7
LI = lambda : [int(k) for k in input().split()]
input = lambda : sys.stdin.readline().rstrip()
IN = lambda : int(input())
S = lambda : input()
r = range
for t in r(IN()):
	n = IN()
	arr = LI()
	index = {}
	ans = 0
	for i in range(n):
		index[arr[i]] = i + 1
	arr.sort()
	for i in range(n):
		for j in range(i + 1, n):
			pro = arr[i] * arr[j]
			if pro < 2 * n:
				ind = index[arr[i]] + index[arr[j]]
				if ind == pro:
					ans += 1
			else:
				break
	print(ans)


t = int(input())
for ttt in range(0, t):
	n = int(input())
	n2 = n + n
	s = input().split()
	a = [0] * n
	for i in range(n):
		a[i] = int(s[i])
	k = 0
	for i in range(n - 1):
		aj = 1
		while aj <= n2 // a[i]:
			j = aj * a[i] - i - 2
			if j > i and j < n and (a[j] == aj):
				k += 1
			aj += 1
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	temp = 0
	x = list(map(int, input().split()))
	for i in range(n):
		for j in range(x[i] - i - 2, n, x[i]):
			if i < j and x[i] * x[j] == i + j + 2:
				temp += 1
	print(temp)


from math import floor

def main():
	n = int(input())
	a = ['_'] + [int(x) for x in input().split()]
	ans = 0
	for i in range(1, n + 1):
		j = a[i] - i
		if j < i:
			k = 2 * i // a[i]
			j = k * a[i] - i + a[i]
		while j <= n:
			if a[i] * a[j] == i + j:
				ans += 1
			j += a[i]
	print(ans)
t = int(input())
for _ in range(t):
	main()


def count(temp, n):
	c = 0
	for i in range(n):
		for j in range(i + 1, n):
			left = temp[i][0] * temp[j][0]
			right = temp[i][1] + temp[j][1]
			if left == right:
				c += 1
			if left > 2 * n:
				break
	return c
for _ in range(int(input())):
	ans = 0
	n = int(input())
	temp = []
	l = list(map(int, input().split()))
	for (i, j) in enumerate(l):
		temp.append([j, i + 1])
	temp.sort()
	ans = count(temp, n)
	print(ans)


for _ in range(int(input())):
	x = int(input())
	zoop = list(map(int, input().split()))
	zoop.insert(0, 0)
	ans = 0
	for i in range(1, len(zoop)):
		for j in range(zoop[i] - i, len(zoop), zoop[i]):
			if j >= 0:
				if zoop[i] * zoop[j] == i + j and i < j:
					ans += 1
	print(ans)


import sys
input = sys.stdin.readline

def pleasantPairs(n, arr):
	res = 0
	for j in range(1, n + 1):
		if arr[j] >= 2 * j:
			continue
		tmp = 1
		while tmp * arr[j] < 2 * j:
			i = tmp * arr[j] - j
			if i > 0 and arr[i] == tmp:
				res += 1
			tmp += 1
	return res

def main():
	for t in range(int(input())):
		n = int(input())
		arr = [-1]
		for i in input().split():
			arr.append(int(i))
		print(pleasantPairs(n, arr))
main()


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for (i, x) in enumerate(a, 2):
		for j in range(-i % x, i - 2, x):
			if i + j == x * a[j]:
				ans += 1
	print(ans)
for _ in range(int(input())):
	solve()


from math import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = [-1] + li()
		print(sum((i + j == x * a[j] for (i, x) in enumerate(a) for j in range(-i % x, i, x))))
solve()


import math

def pleasantPairs(n, array):
	ans = 0
	array = [0] + array
	for x in range(1, n + 1):
		f = (2 * x - array[x]) // array[x] + 1
		start = array[x] * f + array[x] - x
		for y in range(start, n + 1, array[x]):
			if array[x] * array[y] == x + y:
				ans += 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(pleasantPairs(n, l))


from math import ceil
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = 0
	for (p, x) in enumerate(a):
		i = p + 1
		for k in range(x * ceil((2 * i + 1) / x), i + n + 1, x):
			if a[k - i - 1] == k // a[p]:
				s += 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	lst = [0]
	lst1 = [int(x) for x in input().split()]
	lst.extend(lst1)
	sum = 0
	for j in range(1, n + 1):
		x = (j + j - 1) % lst[j]
		x += 1
		i = j - x
		while i > 0:
			if lst[j] * lst[i] == i + j:
				sum += 1
			i -= lst[j]
	print(sum)


n = int(input())
for m in range(n):
	x = int(input())
	l = list(map(int, input().split()))
	k = 0
	for i in range(1, x):
		b = -i % l[i - 1]
		for j in range(b, x + 1, l[i - 1]):
			if l[i - 1] * l[j - 1] == i + j and j > i:
				k = k + 1
	print(k)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	l = [0] + list(map(int, input().split(' ')))
	ans = 0
	for i in range(1, n + 1):
		start = l[i] - i % l[i]
		while start <= n:
			if l[i] * l[start] == start + i:
				ans += 1
				if i == start:
					ans -= 1
			start += l[i]
	print(ans // 2)


t = int(input())
for i in range(0, t):
	n = int(input())
	a1 = input().split()
	a = [int(x) for x in a1]
	cont = 0
	for i in range(0, n):
		p = a[i]
		for j in range(i + p - 2 * (i + 1) % p, n, p):
			if p * a[j] == i + j + 2:
				cont += 1
	print(cont)


def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def msi():
	return map(str, input().split())

def li():
	return list(mi())
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	cnt = 0
	for i in range(n):
		for j in range(a[i] - i - 2, n, a[i]):
			if a[i] * a[j] == i + j + 2 and i < j:
				cnt += 1
	print(cnt)


from bisect import *
import math

def solve(arr):
	work = [(val, index) for (index, val) in enumerate(arr)]
	work.sort()
	ctr = 0
	prevPosn = len(work)
	for x in range(len(work)):
		(cand1val, cand1idx) = work[x]
		upperLim = int(math.ceil(len(work) / cand1val)) * 2
		posn = bisect_left(work, (upperLim, 0), 0, min(prevPosn + 2, len(work)))
		for y in range(min(posn + 1, len(work) - 1), x, -1):
			(cand2val, cand2idx) = work[y]
			if cand1val * cand2val == cand1idx + cand2idx + 2:
				ctr += 1
		prevPosn = posn
	return ctr
t = int(input())
for test in range(1, t + 1):
	_ = int(input())
	arr = map(int, input().split())
	print(f'{solve(arr)}')


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		ans = 0
		for i in range(n):
			if a[i] <= i + n + 1:
				for j in range(a[i] - i - 2, n, a[i]):
					if a[i] * a[j] == i + j + 2 and j > i:
						ans += 1
		print(ans)
main()


import math
from sys import stdin
im = float('inf')
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	l = [im] * (2 * n + 3)
	for i in range(n):
		l[a[i]] = i + 1
	count = 0
	for i in range(3, 2 * n):
		for j in range(1, int(math.sqrt(i)) + 1):
			if i % j == 0 and i != j * j:
				if l[j] + l[int(i / j)] == i:
					count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	a.insert(0, 0)
	pairs = 0
	for i in range(2, n + 1):
		j = (i // a[i] + 1) * a[i] - i
		for k in range(j, i, a[i]):
			if a[i] * a[k] == i + k:
				pairs += 1
	print(pairs)


T = int(input())
for t in range(T):
	n = int(input())
	st = input().split()
	A = [0] + [int(st[i]) for i in range(n)]
	result = 0
	for i in range(1, n):
		a = A[i]
		m = 1
		j = m * a - i
		while j < n + 1:
			if j > i:
				if A[j] * A[i] == j + i:
					result += 1
			m += 1
			j = m * a - i
	print(result)


import sys
input = sys.stdin.readline

def I():
	return input().strip()

def II():
	return int(input().strip())

def LI():
	return [*map(int, input().strip().split())]
import copy, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter, OrderedDict
from itertools import permutations, combinations, groupby
from operator import itemgetter
for _ in range(II()):
	n = II()
	l = LI()
	l1 = []
	l2 = []
	c = 0
	for i in range(n):
		if l[i] <= (2 * n) ** 0.5:
			l1.append([l[i], i + 1])
		else:
			l2.append([l[i], i + 1])
	for i in range(len(l1) - 1):
		for j in range(i + 1, len(l1)):
			if l1[i][0] * l1[j][0] == l1[i][1] + l1[j][1]:
				c = c + 1
	for i in range(len(l1)):
		for j in range(len(l2)):
			if l1[i][0] * l2[j][0] == l1[i][1] + l2[j][1]:
				c = c + 1
	print(c)


t = int(input())
for __ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	r = {}
	for i in range(n):
		d[l[i]] = i + 1
		r[i + 1] = l[i]
	c = 0
	for i in range(n):
		j = 1
		while 1:
			t = l[i] * j - (i + 1)
			if t > n:
				break
			if t > i + 1 and t in r and (r[t] == j):
				c += 1
			j += 1
	print(c)


def pairs(n, arr):
	hset = set()
	for i in range(1, n + 1):
		j = i + 1
		temp = 1
		while j <= n + 1:
			j = arr[i - 1] * temp - i
			if j > i and j <= n and (arr[j - 1] == temp):
				hset.add((i, j))
			temp += 1
	return len(hset)
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(pairs(n, arr))


for _ in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	result = 0
	for i in range(1, n):
		for j in range(arr[i - 1] - i % arr[i - 1], n + 1, arr[i - 1]):
			if i >= j:
				continue
			if i + j == arr[i - 1] * arr[j - 1]:
				result += 1
	print(result)


for _ in range(int(input())):
	n = int(input())
	L = [x for x in map(int, input().split())]
	s = 0
	for i in range(1, n + 1):
		j0 = L[i - 1] - i % L[i - 1]
		for j in range(j0, i, L[i - 1]):
			if L[i - 1] * L[j - 1] == i + j:
				s += 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	for i in range(1, n + 1):
		x = a[i - 1]
		for j in range(x - i % x, n + 1, x):
			if x * a[j - 1] == i + j and i < j:
				c += 1
	print(c)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = inp()
	l = li()
	ans = 0
	d = {l[i - 1]: i for i in range(1, n + 1)}
	for i in range(3, 2 * n):
		j = 1
		while j * j <= i:
			if i % j == 0:
				if j != i // j:
					if j in d and i // j in d:
						s = d[j] + d[i // j]
						if s == i:
							ans += 1
			j += 1
	pr(ans)
for _ in range(inp()):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	w = list(map(int, input().split()))
	o = []
	for i in range(n):
		o.append([w[i], i + 1])
	o = sorted(o)
	z = 0
	for i in range(n):
		for j in range(i + 1, n):
			if o[i][0] * o[j][0] == o[i][1] + o[j][1]:
				z += 1
			if o[i][0] * o[j][0] > 2 * n:
				break
	print(z)


import os
import sys
from io import BytesIO, IOBase
from math import ceil, floor, pow, sqrt, gcd
from collections import Counter, defaultdict
from itertools import permutations, combinations
from time import time, sleep
BUFSIZE = 8192
MOD = 1000000007

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from os import path
if path.exists('tc.txt'):
	stdin = open('tc.txt', 'r')

def gmi():
	return map(int, stdin.readline().strip().split())

def gms():
	return map(str, stdin.readline().strip().split())

def gari():
	return list(map(int, stdin.readline().strip().split()))

def gart():
	return tuple(map(int, stdin.readline().strip().split()))

def gars():
	return list(map(str, stdin.readline().strip().split()))

def gs():
	return stdin.readline().strip()

def gls():
	return list(stdin.readline().strip())

def gi():
	return int(stdin.readline())

def pri(i, end='\n'):
	stdout.write(f'{i}' + end)

def priar(ar, end='\n'):
	stdout.write(' '.join(map(str, ar)) + end)

def solve():
	n = gi()
	ar = gari()
	mp = dict([(ar[i], i + 1) for i in range(n)])
	mx = max(ar)
	ans = 0
	for i in range(n):
		for j in range(1, (i + 1 + n) // ar[i] + 1):
			if j in mp and mp[j] + i + 1 == ar[i] * j and (i + 1 < mp[j]):
				ans += 1
	return ans
tc = gi()
for i in range(tc):
	pri(solve())


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	n = iinp()
	arr = lmp()
	arr = [-1] + arr
	ans = 0
	for i in range(1, n + 1):
		x = i % arr[i]
		for j in range((round(i / arr[i]) + 1) * arr[i] - x, n + 1, arr[i]):
			if arr[j] == (i + j) // arr[i]:
				ans += 1
	print(ans)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	ans = 0
	for i in range(1, n + 1):
		for j in range(arr[i - 1] - i, n + 1, arr[i - 1]):
			if j <= i:
				continue
			if i + j == arr[i - 1] * arr[j - 1]:
				ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	q = 2 * n
	li = list(map(int, input().split()))
	arr = []
	count = 0
	for i in range(n):
		arr.append([li[i], i + 1])
	arr.sort()
	i = 0
	while i < n - 1:
		a = arr[i][0]
		j = i + 1
		while j < n:
			b = arr[j][0]
			if b < q:
				x = arr[i][1] + arr[j][1]
				y = a * b
				if x == y:
					count += 1
				elif y >= q:
					n = j
			j += 1
		i += 1
	print(count)


import collections
import math
import bisect
import heapq
t = int(input())
for w in range(t):
	n = int(input())
	arr = [0]
	v = [int(x) for x in input().split()]
	arr.extend(v)
	count = 0
	for i in range(1, n + 1):
		j = arr[i]
		while j - i <= i:
			j += arr[i]
		while j - i <= n:
			if arr[j - i] == j / arr[i]:
				count += 1
			j += arr[i]
	print(count)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.insert(0, 0)
	ans = 0
	for i in range(1, n + 1):
		start = l[i] - i
		for j in range(start, n + 1, l[i]):
			if j >= 0:
				if l[i] * l[j] == i + j and i < j:
					ans += 1
	print(ans)


import math
from collections import deque
import os
import sys
from io import BytesIO, IOBase

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
for _ in range(inp()):
	n = inp()
	l = inlt()
	d = {}
	c = 0
	for i in range(2 * n):
		d[i + 1] = {}
	for i in range(n):
		if i + 1 in d[l[i]]:
			c += d[l[i]][i + 1]
		a = l[i]
		k = a
		j = 1
		while a <= 2 * n:
			x = l[i] * j - i - 1
			if x not in d[j]:
				d[j][l[i] * j - i - 1] = 1
			else:
				d[j][l[i] * j - i - 1] += 1
			j += 1
			a = k * j
	print(c)


from sys import stdin
lst = list(map(int, stdin.read().split()))
_s = 0

def inp(n=1):
	global _s
	ret = lst[_s:_s + n]
	_s += n
	return ret

def inp1():
	return inp()[0]
t = inp1()
for _ in range(t):
	n = inp1()
	a = inp(n)
	ret = 0
	for i in range(1, n + 1):
		x = a[i - 1]
		d = x - i % x
		for j in range(d, n + 1, x):
			if i == j:
				continue
			if i + j == x * a[j - 1]:
				ret += 1
	print(ret // 2)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n):
		arr[i] = [arr[i], i + 1]
	arr.sort()
	ans = 0
	for i in range(n):
		k = arr[i][0]
		j = i + 1
		while j < n and arr[j][0] <= 2 * n // k:
			if arr[j][0] * arr[i][0] == arr[i][1] + arr[j][1]:
				ans += 1
			j += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = {}
	for i in range(n):
		a[l[i]] = i + 1
	l.sort()
	c = 0
	for i in range(1, n):
		k = l[i]
		for j in range(i):
			if l[j] * k > 2 * n - 1:
				break
			if l[j] * k == a[l[j]] + a[k]:
				c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	ans = 0
	was = {}
	for i in range(n):
		j = 1
		while s[i] * j <= 2 * (i + 1):
			if j not in was:
				j += 1
				continue
			if s[i] * j == i + was[j] + 1:
				ans += 1
			j += 1
		was[s[i]] = i + 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	for j in range(1, n):
		if (j + 1) // l[j] == 0:
			i = l[j] - (j + 1)
		else:
			i = l[j] - (j + 1) % l[j]
		while i < j + 1:
			if l[i - 1] == (i + j + 1) // l[j]:
				count += 1
			i += l[j]
	print(count)


n = int(input())
for _ in range(n):
	amount = int(input())
	l = list(input().split())
	l = list(map(int, l))
	count = 0
	for i in range(amount):
		if i == 0:
			continue
		j = 0
		t = 0
		while True:
			t += l[i]
			j = t - 2 - i
			if j < 0:
				continue
			if j >= i:
				break
			if l[i] * l[j] == i + j + 2:
				count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	arr.insert(0, 0)
	for x in range(1, len(arr)):
		for y in range(arr[x] - x, len(arr), arr[x]):
			if y >= 0:
				if arr[y] * arr[x] == x + y and x > y:
					ans += 1
	print(ans)