Time limit: c/s + + 1 seconds, other languages 2 seconds

Space restrictions: C/C + + 131072K, other languages 262144K

64bit IO Format:%lld

Topic description

Given an array A with length n a[1],a[2],..., a[n] where A[i] (1<=i<=n) is positive integer.

Count the number of pair (L,R) such that a[l],a[l+1],..., A[r] Can is rearranged to form a geometric sequence.

Geometric sequence is ' an array where ' term after the ' is ' found by multiplying ' previous one by a fixed, non-ze RO number called the common ratio. i.e. a = [1,2,4,8,16] is a geometric sequence.

Enter a description:

The 1 <= n <= 100000.

The second line consists of N-integer a[1],a[2],..., a[n] where a[i] <= 100000 for 1<=i<=n.

Output Description:

An integer answer for the problem.

Example 1

Input

5

1 1 2 4 1

Output

11

Description

The pairs of (l,r) are (1,1), (1,2), (2,2), (2,3), (2,4), (3,3), (3,4), (3,5), (4,4), (4,5), (5,5).

Example 2

Input

10

3 1 1 1 5 2 2 5 3 3

Output

20

Note:

The answer can be quite large and you could use long long in C + + or the similar in other languages.

Let you find all of the equal-ratio sequences.

Analysis: Reverse thinking can be a graceful violence. Since the data is less than 100,000, the 2 sequence length is 17, so we can enumerate the length of the sequence.

is the male ratio not a decimal? Of course, but if it's a decimal, it can be converted into fractions, then it must be the integer power of the denominator. The minimum denominator, however, is 2, so the certificate.

Note: When the game is in the precision of the card, card in 90% of the data is not past. Never double with a long int that can be resolved later.

#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace
Std
#define LL long int const double EPS = 1e-8;
const int MAXN = 1e5 + 10;
Double A[MAXN];
Double B[MAXN];
int main () {int n;
scanf ("%d", &n);
for (int i = 1; I <= n; i++) {scanf ("%lf", &a[i));
B[i] = A[i];
ll ans = 2*n-1;
for (int i = 1; I <= n; i++) {for (int j = 1; J <=-J) {if (i + j-1 > N) break;
if (j = = 1 | | j = = 2) {Continue}
Sort (A + I, a + i + j);
Double cs = a[i + 1]/a[i];
int flag = 1;
for (int k = i + 1; k <= i + j-1; k++) {Double ct = a[k]/a[k-1];
if (Fabs (CT-CS) > EPS) {flag = 0;
} if (Fabs (cs-1) < EPS) flag = 0;
Ans + 1ll * flag; cout << Flag << Endl;
for (int k = i; k <= i + j-1; k++) {a[k] = b[k];
}} ll sum = 1;
for (int i = 2; I <= n; i++) {if (a[i] = = a[i-1]) sum++;
else sum = 1;
if (sum>=3) ans = ans + sum-2;
printf ("%lld\n", ans);
return 0; }