305433: CF1030G. Linear Congruential Generator

Memory Limit:512 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Linear Congruential Generator

题意翻译

你有 $n$ 个线性同余生成器,每个生成器有 $f_0,a,b,p$ 四个属性,生成方式为 $f_i=(af_{i-1}+b)\bmod p$。你需要生成长为 $n$ 的序列,第 $i$ 个序列(从 $0$ 标号)的第 $j$ 个元素为第 $j$ 个生成器生成的 $f_i$ 项。现在给定每个生成器的 $p$,你可以任意挑选每个生成器的 $f_0,a,b$(为 $[0,p)$ 中的整数),问最多能生成多少不同的长为 $n$ 的序列。输出答案模 $10^9+7$ 的值。$n\leqslant 2\times 10^5$,$p_i\leqslant 2\times 10^6$,$p$ 是质数。

题目描述

You are given a tuple generator $ f^{(k)} = (f_1^{(k)}, f_2^{(k)}, \dots, f_n^{(k)}) $ , where $ f_i^{(k)} = (a_i \cdot f_i^{(k - 1)} + b_i) \bmod p_i $ and $ f^{(0)} = (x_1, x_2, \dots, x_n) $ . Here $ x \bmod y $ denotes the remainder of $ x $ when divided by $ y $ . All $ p_i $ are primes. One can see that with fixed sequences $ x_i $ , $ y_i $ , $ a_i $ the tuples $ f^{(k)} $ starting from some index will repeat tuples with smaller indices. Calculate the maximum number of different tuples (from all $ f^{(k)} $ for $ k \ge 0 $ ) that can be produced by this generator, if $ x_i $ , $ a_i $ , $ b_i $ are integers in the range $ [0, p_i - 1] $ and can be chosen arbitrary. The answer can be large, so print the remainder it gives when divided by $ 10^9 + 7 $

输入输出格式

输入格式


The first line contains one integer $ n $ ( $ 1 \le n \le 2 \cdot 10^5 $ ) — the number of elements in the tuple. The second line contains $ n $ space separated prime numbers — the modules $ p_1, p_2, \ldots, p_n $ ( $ 2 \le p_i \le 2 \cdot 10^6 $ ).

输出格式


Print one integer — the maximum number of different tuples modulo $ 10^9 + 7 $ .

输入输出样例

输入样例 #1

4
2 3 5 7

输出样例 #1

210

输入样例 #2

3
5 3 3

输出样例 #2

30

说明

In the first example we can choose next parameters: $ a = [1, 1, 1, 1] $ , $ b = [1, 1, 1, 1] $ , $ x = [0, 0, 0, 0] $ , then $ f_i^{(k)} = k \bmod p_i $ . In the second example we can choose next parameters: $ a = [1, 1, 2] $ , $ b = [1, 1, 0] $ , $ x = [0, 0, 1] $ .

Input

题意翻译

你有 $n$ 个线性同余生成器,每个生成器有 $f_0,a,b,p$ 四个属性,生成方式为 $f_i=(af_{i-1}+b)\bmod p$。你需要生成长为 $n$ 的序列,第 $i$ 个序列(从 $0$ 标号)的第 $j$ 个元素为第 $j$ 个生成器生成的 $f_i$ 项。现在给定每个生成器的 $p$,你可以任意挑选每个生成器的 $f_0,a,b$(为 $[0,p)$ 中的整数),问最多能生成多少不同的长为 $n$ 的序列。输出答案模 $10^9+7$ 的值。$n\leqslant 2\times 10^5$,$p_i\leqslant 2\times 10^6$,$p$ 是质数。

加入题单

算法标签: