#P9607. [CERC2019] Be Geeks!

    ID: 10595 远端评测题 2000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2019线段树倍增ST 表ICPC笛卡尔树单调栈

[CERC2019] Be Geeks!

Background

This problem is translated from CERC 2019Be Geeks!”.

Problem Description

The music band Be Geeks! did not get its name by accident, because all members are true math geeks. Besides that, they like to study various properties of sequences. Here is an example they are interested in:

  • Let AA be a non-empty sequence of positive integers, A=(a1,a2,,aN)A=(a_1, a_2, \dots, a_N).
  • G(i,j)=gcd(ai,ai+1,,aj)G(i, j)=\gcd (a_i, a_{i+1}, \dots, a_j), where 1ijN1\le i\le j\le N.
  • M(i,j)=max(ai,ai+1,,aj)M(i, j)=\max (a_i, a_{i+1}, \dots, a_j), where 1ijN1\le i\le j\le N.
  • P(i,j)=G(i,j)×M(i,j)P(i, j)=G(i, j)\times M(i, j), where 1ijN1\le i\le j\le N.
  • F(A)=P(i,j)[1ijN]F(A)=\sum P(i, j)[1\le i\le j\le N].

Given a sequence AA, you need to compute F(A)mod1000000007F(A)\bmod 1\,000\,000\,007.

Input Format

The first line contains an integer N (1N2×105)N\ (1\le N\le 2\times 10^5), which is the length of sequence AA.

The second line contains NN integers a1,a2,,aN (1ai109)a_1, a_2, \dots, a_N\ (1\le a_i\le 10^9), representing the sequence AA.

Output Format

Output one integer, which is the value of F(A)mod1000000007F(A)\bmod 1\,000\,000\,007.

4
1 2 3 4

50

5
2 4 6 12 3

457

Hint

Translated by ChatGPT 5