#P8469. [Aya Round 1 D] 文文的数学游戏

    ID: 9538 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>2022数论洛谷原创O2优化最大公约数 gcd组合数学洛谷月赛

[Aya Round 1 D] 文文的数学游戏

Background

After solving the previous problem, Cirno felt as if she were a genius. So, Shameimaru Aya gave her another simple math problem.

Problem Description

Given an integer sequence aa of length nn, you need to construct an integer sequence bb of length nn such that for all 1in1 \le i \le n, we have 1biai1 \le b_i \le a_i. Also, gcd(b1,b2,,bn)\gcd(b_1,b_2,\cdots,b_n) should be as large as possible, where gcd\gcd denotes the greatest common divisor. Find the maximum possible value and, when this maximum is achieved, the number of different sequences bb, modulo 109+710^9+7.

Two sequences c,dc, d of length LL are considered different if and only if there exists an integer i(1iL)i(1 \le i \le L) such that cidic_i \ne d_i.

Input Format

  • The first line contains an integer nn.
  • The second line contains nn integers, representing the sequence aa.

Output Format

  • Output one line with two integers: the maximum gcd(b1,b2,,bn)\gcd(b_1,b_2,\cdots,b_n) that can be obtained, and the number of corresponding different sequences bb achieving this maximum, modulo 109+710^9+7.
3
1 2 3
1 6

Hint

Sample 1 Explanation

Note that since 1b1a1=11 \le b_1 \le a_1 = 1, b1b_1 must be 11. Therefore, the maximum possible gcd\gcd value can only be 11. Under this condition, all valid bb are as follows:

  • $\{1,1,1\},\{1,1,2\},\{1,1,3\},\{1,2,1\},\{1,2,2\},\{1,2,3\}$.

Constraints

For 100%100\% of the testdata, 1n1051 \le n \le 10^5, 1ai1091 \le a_i \le 10^9.

This problem comes with a set of large samples.

Translated by ChatGPT 5