【题解】codeforces1058G[Codeforces Round #512 Div.2]G.Linear Congruential Generator LCM+数学知识

32 篇文章 0 订阅
32 篇文章 0 订阅

Description

You are given a tuple generator f ( k ) = ( f 1 ( k ) , f 2 ( k ) , ⋯   , f n ( k ) ) f^{(k)}=(f^{(k)}_1,f^{(k)}_2,\cdots,f^{(k)}_n) f(k)=(f1(k),f2(k),,fn(k)), where f i ( k ) = ( a i ⋅ f i ( k − 1 ) + b i ) m o d    p i f^{(k)}_i=(a_i⋅f^{(k−1)}_i+b_i)\mod p_i fi(k)=(aifi(k1)+bi)modpi and f ( 0 ) = ( x 1 , x 2 , ⋯   , x n ) f^{(0)}=(x_1,x_2,\cdots,x_n) f(0)=(x1,x2,,xn). Here x m o d    y x\mod y xmody denotes the remainder of x x x when divided by y y y. All p i p_i pi are primes.

One can see that with fixed sequences x i , y i , a i x_i, y_i, a_i xi,yi,ai 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 ) f^{(k)} f(k) for k ≥ 0 k≥0 k0) that can be produced by this generator, if x i , a i , b i x_i, a_i, b_i xi,ai,bi are integers in the range [ 0 , p i − 1 ] [0,p_i−1] [0,pi1] and can be chosen arbitrary. The answer can be large, so print the remainder it gives when divided by 1 0 9 + 7 10^9+7 109+7

Input

The first line contains one integer n n n ( 1 ≤ n ≤ 2 × 105 ) (1≤n≤2\times105) (1n2×105) — the number of elements in the tuple.

The second line contains n n n space separated prime numbers — the modules p 1 , p 2 , ⋯   , p n p_1,p_2,\cdots,p_n p1,p2,,pn ( 2 ≤ p i ≤ 2 × 1 0 6 ) (2≤p_i≤2\times10^6) (2pi2×106).

Output

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

Examples

Input

4
2 3 5 7

Output

210

Input

3
5 3 3

Output

30

Note

In the first example we can choose next parameters: a = [ 1 , 1 , 1 , 1 ] , b = [ 1 , 1 , 1 , 1 ] , x = [ 0 , 0 , 0 , 0 ] a=[1,1,1,1], b=[1,1,1,1], x=[0,0,0,0] a=[1,1,1,1],b=[1,1,1,1],x=[0,0,0,0], then f i ( k ) = k m o d    p i f^{(k)}_i=k\mod p_i fi(k)=kmodpi.

In the second example we can choose next parameters: a = [ 1 , 1 , 2 ] , b = [ 1 , 1 , 0 ] , x = [ 0 , 0 , 1 ] a=[1,1,2], b=[1,1,0], x=[0,0,1] a=[1,1,2],b=[1,1,0],x=[0,0,1].


感觉整道题非常玄学。在围观大佬题解官方题解后,大概明白了啥意思。这个函数图像是一个圆圈还有圈外的一部分。最后答案是 l c m i = 1 ⋯ n ( c i ) lcm_{i=1\cdots n}(c_i) lcmi=1n(ci)+ max ⁡ i = 1 ⋯ n ( p p i ) \max\limits_{i=1\cdots n}(pp_i) i=1nmax(ppi)。中间噼里啪啦一堆公式看的我酸爽,反正就证明了 max ⁡ i = 1 ⋯ n ( p p i ) = 1 \max\limits_{i=1\cdots n}(pp_i)=1% i=1nmax(ppi)=1以及我们需要 p i − 1 p_i-1 pi1 的因子。然后就是求一个 l c m lcm lcm,如果 p i p_i pi 加过了就加 p i − 1 p_i-1 pi1,然后就稀里糊涂写()一遍就过了。

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=2e6+10;
const int mod=1e9+7;
int prime[N],pp,pri[N],ans=1,p[N],n,cnt[N],mx[N];
bool iscomp[N];
void primetable()
{
	for(int i=2;i<N;i++)
	{
		if(!iscomp[i])prime[pp++]=i,pri[i]=i;
		for(int j=0;j<pp&&1ll*i*prime[j]<N;j++)
		{
			iscomp[i*prime[j]]=1;
			pri[i*prime[j]]=prime[j];
			if(i%prime[j]==0)break;
		}
	}
}
int main()
{
	//freopen("in.txt","r",stdin);
	primetable();
	scanf("%d\n",&n);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
    sort(p+1,p+n+1);
    for(int i=n;i;i--)
    {
    	if(!cnt[p[i]])cnt[p[i]]++,mx[p[i]]=1,ans=(1ll*ans*p[i])%mod;
    	else
    	{
    		int v=--p[i];
    		while(v!=1)
    		{
    			int u=pri[v],ci=0;
    			while(v%u==0)v/=u,ci++;
    			if(cnt[u]<ci)
    			{
    				for(int j=cnt[u]+1;j<=ci;j++)ans=(1ll*ans*u)%mod;
    				cnt[u]=ci;mx[u]=1;
				}
				else mx[u]+=(cnt[u]==ci);
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		int v=p[i],flag=0;
		while(v!=1)
		{
			int u=pri[v],ci=0;
			while(v%u==0)v/=u,ci++;
			if(cnt[u]==ci&&mx[u]==1)flag=1;
		}
		if(!flag)
		{
			ans++;break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

总结

玄学数论,还有那个啥拉格朗日定理是啥……
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值