概述
The Little Elephant loves the LCM (least common multiple) operation of a non-empty set of positive integers. The result of the LCM operation of k positive integers x1, x2, ..., xk is the minimum positive integer that is divisible by each of numbers xi.
Let's assume that there is a sequence of integers b1, b2, ..., bn. Let's denote their LCMs as lcm(b1, b2, ..., bn) and the maximum of them as max(b1, b2, ..., bn). The Little Elephant considers a sequence b good, if lcm(b1, b2, ..., bn) = max(b1, b2, ..., bn).
The Little Elephant has a sequence of integers a1, a2, ..., an. Help him find the number of good sequences of integers b1, b2, ..., bn, such that for all i (1 ≤ i ≤ n) the following condition fulfills: 1 ≤ bi ≤ ai. As the answer can be rather large, print the remainder from dividing it by 1000000007 (109 + 7).
The first line contains a single positive integer n (1 ≤ n ≤ 105) — the number of integers in the sequence a. The second line contains nspace-separated integers a1, a2, ..., an (1 ≤ ai ≤ 105) — sequence a.
In the single line print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
4 1 4 3 2
15
2 6 3
13
如:a=[1, 2 ,3 ,4 ] 4
枚举最大值 2,2,2
首先是4,a数列中各数包含4的因子分别为 1,1,1,1 ,那么最大值为4时的b数列的方案数为1*2*2*(4-3)=4种。因为要满足最大值为4,所以最后只能取4.
3,3
其次是3,a数列中各数包含3的因子分别为 1,1 ,1,1 ,那么最大值为3时的b数列的方案数为1*1*(2*2-1)=3种。因为要满足最大值为3,所以最后有3种取法。
以此类推。
#include<bits/stdc++.h>
typedef __int64 ll;
using namespace std;
const int MOD=1e9+7;
const int MAX_N = 1e6;
int all=0,p[MAX_N],m;
int pr[MAX_N+100],a[MAX_N];
bool isp[MAX_N+10];
void init()
{
all = 0;
memset(isp,0,sizeof isp);
isp[1]=1;
for(int i=2;i<=MAX_N;i++)
{
if(!isp[i])pr[all++] = i;
for(int j=0;j<all;j++)
{
ll t = (ll)1*pr[j]*i ;
if(t<=MAX_N)
{
isp[t] = true;
if(i%pr[j]==0)break;
}
else break;
}
}
}
void dive(int x)
{
m=0;
for(int i=1;i*i<=x;i++)
{
if(x%i==0)
{
p[m++]=i;
if(x/i!=i)p[m++]=x/i;
}
}
sort(p+1,p+m);
}
ll POW(ll x,ll y)
{
ll res=1;
while(y)
{
if(y&1)res=res*x%MOD;
x=(x*x)%MOD;
y/=2;
}
return res%MOD;
}
int main()
{
init();
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)scanf("%d",&a[i]);
sort(a,a+n);
ll ans=0;
for(int i=a[n-1];i>=1;i--)
{
dive(i);
ll st=0,now=1;
for(int j=1;j<m;j++)
{
ll en=lower_bound(a,a+n,p[j])-a;
now=now*POW(j,en-st)%MOD;
st=en;
}
now=now*(((POW(m,n-st)-POW(m-1,n-st))%MOD+MOD)%MOD)%MOD;
ans=(ans+now)%MOD;
}
cout<<ans<<endl;
}
最后
以上就是难过板栗为你收集整理的Codeforces-258C:Little Elephant and LCM(数论)的全部内容,希望文章能够帮你解决Codeforces-258C:Little Elephant and LCM(数论)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复