luogu#P8912. [RC-06] ijk

[RC-06] ijk

Problem Description

Given a sequence [a1,a2,a3,,an][a_1,a_2,a_3,\dots,a_n], it is guaranteed that i[2,n],aiai1\forall i\in [2,n], a_i\ge a_{i-1}.

Compute how many integer triples (i,j,k)(i,j,k) satisfy:

  • 1i,j,kn1\le i,j,k\le n.
  • ai×j×ak=i+aj+ka_i\times j\times a_k=i+a_j+k.

Input Format

The first line contains a positive integer nn.

The second line contains nn positive integers a1,a2,,ana_1,a_2,\dots,a_n. It is guaranteed that aiai1a_i\ge a_{i-1}.

Output Format

Output one line with one non-negative integer, which is the answer.

5
2 3 3 4 5
3
10
1 1 2 2 3 3 4 4 5 8
25

Hint

This problem has three subtasks.

All testdata satisfy: 1n1061\le n\le 10^6, 1ai1061\le a_i\le 10^6, aiai1a_i\ge a_{i-1}.

  • Subtask 11 (55 points): n500n\le 500.
  • Subtask 22 (55 points): ai10a_i\le 10.
  • Subtask 33 (9090 points): no special constraints.

Translated by ChatGPT 5