bzoj 3560 DZY Loves Math V

3560: DZY Loves Math V
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 325 Solved: 180
[Submit][Status][Discuss]
Description

给定n个正整数a1,a2,…,an,求

这里写图片描述

的值(答案模10^9+7)。

Input

第一行一个正整数n。

接下来n行,每行一个正整数,分别为a1,a2,…,an。

Output

仅一行答案。

Sample Input

3

6

10

15

Sample Output

1595

HINT

1<=n<=10^5,1<=ai<=10^7。共3组数据。

Source

By Jcvb


【分析】
懒…写不了题解QaQ


【代码】

//bzoj 3560 DZY Loves Math V
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 3500
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=100005;
const int mod=1e9+7;
int n,cnt,ans=1;
int vis[4000],pri[4000],sum[mxn];
struct node
{
    int x,y;
}a[1000005];
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline bool comp(node a,node b)
{
    if(a.x==b.x) return a.y>b.y;
    return a.x<b.x;
}
inline int ksm(int x,int k)
{
    if(k==1) return x;
    int tmp=ksm(x,k>>1);
    if(k&1) return (ll)tmp*tmp%mod*x%mod;
    else return (ll)tmp*tmp%mod;
}
inline void init()
{
    int i,j;
    sum[0]=1;
    fo(i,2,N)
    {
        if(!vis[i]) pri[++pri[0]]=i;
        for(j=1;j<=pri[0]&&(ll)i*pri[j]<=N;j++)
        {
            vis[i*pri[j]]=1;
            if(i%pri[j]==0) break;
        }
    }
}
inline void get()
{
    int x=read();
    for(int i=1;i<=pri[0] && pri[i]*pri[i]<=x;i++)
      if(x%pri[i]==0)
      {
          int tmp=0;cnt++;
          while(x%pri[i]==0) x/=pri[i],tmp++;
          a[cnt].x=pri[i],a[cnt].y=tmp;
      }
    if(x>1) cnt++,a[cnt].x=x,a[cnt].y=1;
}
int main()
{
    init();
    int i,j,last;
    n=read();
    fo(i,1,n) get();
    sort(a+1,a+cnt+1,comp);
    for(i=1;i<=cnt;i=last+1)
    {
        last=i;
        int tmp=1;
        fo(j,1,a[i].y) sum[j]=(ll)sum[j-1]*a[i].x%mod;
        fo(j,1,a[i].y) sum[j]=(sum[j]+sum[j-1])%mod;
        while(a[last+1].x==a[last].x)
          tmp=(ll)tmp*sum[a[last].y]%mod,last++;
        tmp=(ll)tmp*sum[a[last].y]%mod;
        tmp=(tmp-1+mod)%mod;
        tmp=((ll)tmp*(a[i].x-1)%mod*ksm(a[i].x,mod-2)%mod+1)%mod;
        ans=(ll)ans*tmp%mod;
    }
    printf("%d\n",ans);
    return 0;
}
/*
3
6 10 15
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值