Hdu5288OO's Sequence
// Give a sequence
// Define the f (l, r) function as the range [l, r]
// The number ai is not a multiple of any other number aj in this range.
// Calculate the sum of all f (l, r)
// Find the leftmost interval l [I] And rightmost interval r [I] for each number a [I]
// Include a [I] and make a [I] meet the condition as (I-l [I] + 1) * (r [I]-I + 1)
// For each r [I], traverse from left to right
// Pre [I] indicates the last position of I
// For a number a [I], enumerate all its multiples
// Find the corresponding position on the left of the Cluster. r [pre [j] = I-1;
// Similarly, l [I] can be obtained.
# Include
# Include
# Include
Using namespace std;
Const int maxn = 100010;
Const int mod = 1e9 + 7;
Int a [maxn];
Typedef _ int64 ll;
Ll last [maxn];
Ll pre [maxn];
Ll l [maxn];
Ll r [maxn];
Int main ()
{
// Freopen(in.txt, r, stdin );
Int n;
While (~ Scanf (% d, & n ))
{
Memset (last, 0, sizeof (last ));
Memset (pre, 0, sizeof (pre ));
For (ll I = 1; I <= n; I ++)
{
L [I] = 1; r [I] = n;
Scanf (% d, & a [I]);
For (ll j = a [I]; j <maxn/10; j + = a [I])
If (pre [j]! = 0 & r [pre [j] = n)
R [pre [j] = I-1;
Pre [a [I] = I;
}
For (ll I = n; I> = 1; I --)
{
For (ll j = a [I]; j <maxn/10; j + = a [I])
If (last [j]! = 0 & l [last [j] = 1)
L [last [j] = I + 1;
Last [a [I] = I;
}
Ll ans = 0;
For (ll I = 1; I <= n; I ++)
Ans = (ans + (I-l [I] + 1) % mod) * (r [I]-I + 1) % mod) % mod;
Printf (% I64d, ans );
}
Return 0;
}