BZOJ 3560 DZY Loves Math V 数论
来源:互联网 发布:rrt路径规划算法 编辑:程序博客网 时间:2024/05/16 18:56
题目大意:给定a1,a2,...,an,求
由于φ是积性函数,我们可以将i1i2...in分解质因数,对于每个质因数分开讨论,求积即可
将每个a分解质因数,假设分解后某个质数p在每个ai中的次数分别是bi,那么p对答案的贡献就是
于是对p^j维护一个前缀和,直接计算即可
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define MOD 1000000007using namespace std;struct abcd{ int p,a; bool operator < (const abcd &x) const { if(p!=x.p) return p<x.p; return a<x.a; }}prime_factors[1001001];int n,tot;long long ans=1;void Decomposition(int x){ int i; for(i=2;i*i<=x;i++) if(x%i==0) { prime_factors[++tot].p=i; while(x%i==0) prime_factors[tot].a++,x/=i; } if(x^1) prime_factors[++tot].p=x,prime_factors[tot].a=1;}long long Quick_Power(long long x,long long y){ long long re=1; while(y) { if(y&1) (re*=x)%=MOD; (x*=x)%=MOD;y>>=1; } return re;}void Calculate(int l,int r){ static long long sum[30]; long long p=prime_factors[l].p; long long re=1; int i; sum[0]=1; for(i=1;i<=prime_factors[r].a;i++) sum[i]=sum[i-1]*p%MOD; for(i=1;i<=prime_factors[r].a;i++) (sum[i]+=sum[i-1])%=MOD; for(i=l;i<=r;i++) (re*=sum[prime_factors[i].a])%=MOD; re--;(re*=Quick_Power(p,MOD-2))%=MOD; (re*=p-1,++re)%=MOD; (ans*=re)%=MOD;}int main(){ int i,x; cin>>n; for(i=1;i<=n;i++) { scanf("%d",&x); Decomposition(x); } sort(prime_factors+1,prime_factors+tot+1); for(i=1;i<=tot;i++) { static int last; if(i==tot||prime_factors[i].p!=prime_factors[i+1].p) Calculate(last+1,i),last=i; } cout<<(ans%MOD+MOD)%MOD<<endl; return 0;}
0 0
- BZOJ 3560 DZY Loves Math V 数论
- 【BZOJ 3560】【数论】DZY Loves Math V
- BZOJ 3560 DZY Loves Math V
- 【BZOJ 3560】DZY loves Math V
- bzoj 3560 DZY Loves Math V
- bzoj 3560 DZY Loves Math V
- bzoj3560 DZY Loves Math V 数论
- 数论——bzoj3560: DZY Loves Math V
- bzoj3309 DZY Loves Math 数论
- [bzoj3560] DZY Loves Math V
- BZOJ3560: DZY Loves Math V
- bzoj3560 DZY Loves Math V
- bzoj 3309 DZY Loves Math
- DZY Loves Math [Bzoj 3309]
- BZOJ 3309: DZY Loves Math
- bzoj 3309: DZY Loves Math
- BZOJ 3309 DZY Loves Math
- [数论][莫比乌斯反演][杜教筛] BZOJ 3512: DZY Loves Math IV
- 发布几个google的代理地址
- 修改UISearchBar的Cancel为中文
- Selection in expected linear time O(n)
- 在ASP中 使用 kindeditor-4.1.4编辑器的详细教程
- Android studio 使用Assets文件夹
- BZOJ 3560 DZY Loves Math V 数论
- Simditor上传图片(ASP.NET+JS/Jquery)
- dsa算法(16)
- 三大运营商合力围剿黑卡 重罚违规渠道
- 真正的理解setup time/hold time
- jsp页面中 href传递值
- eclipse导出war包
- (转 博客园Easily)(AS3)基于系统时间的时间管理器Ticker
- Servlet中listener(监听器)和filter的总结