BZOJ3560 : DZY Loves Math V
因为欧拉函数是非完全积性函数,所以可以考虑对每个数进行分解质因数,将每个质数的解乘起来即可。
对于一个质数$p$,设它在各个数中分别出现了$b_1,b_2,...b_n$次,那么由生成函数和欧拉函数的性质得,它对答案的贡献为:
\[(\prod_{i=1}^n\frac{p^{b_i+1}-1}{p-1}-1)\times\frac{p-1}{p}+1\]
#include<cstdio>
const int N=10000010,P=1000000007;
int n,m,i,j,a[100010],tot,p[N],v[N],cnt[N],r[N],f[N],ans=1;
inline void divide(int n){
tot=0;
while(n>1){
if(!cnt[v[n]])p[tot++]=v[n];
cnt[v[n]]++,n/=v[n];
}
for(int i=0;i<tot;i++){
int j=p[i],t=j;
while(cnt[j])t=1LL*t*j%P,cnt[j]--;
f[j]=1LL*(t-1)*r[j-1]%P*f[j]%P;
}
}
int main(){
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&a[i]);
if(a[i]>m)m=a[i];
}
for(r[0]=r[1]=1,i=2;i<=m;i++){
r[i]=(-1LL*r[P%i]*(P/i)%P+P)%P;
if(!v[i])p[tot++]=v[i]=i,f[i]=1;
for(j=0;j<tot;j++){
if(i*p[j]>m)break;
v[i*p[j]]=p[j];
if(i%p[j]==0)break;
}
}
for(i=1;i<=n;i++)divide(a[i]);
for(i=2;i<=m;i++)if(v[i]==i)ans=(1LL*(f[i]+P-1)*(i-1)%P*r[i]+1)%P*ans%P;
return printf("%d",ans),0;
}
BZOJ3560 : DZY Loves Math V的更多相关文章
- BZOJ3560 DZY Loves Math V 数论 快速幂
原文链接http://www.cnblogs.com/zhouzhendong/p/8111725.html UPD(2018-03-26):蒟蒻回来重新学数论了.更新了题解和代码.之前的怼到后面去了 ...
- BZOJ3560 DZY Loves Math V(欧拉函数)
对每个质因子分开计算再乘起来.使用类似生成函数的做法就很容易统计了. #include<iostream> #include<cstdio> #include<cmath ...
- [BZOJ3560]DZY Loves Math V(欧拉函数)
https://www.cnblogs.com/zwfymqz/p/9332753.html 由于欧拉函数是积性函数,可以用乘法分配律变成对每个质因子分开算最后乘起来.再由欧拉函数公式和分配律发现就是 ...
- 【BZOJ 3560】 3560: DZY Loves Math V (欧拉函数)
3560: DZY Loves Math V Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 241 Solved: 133 Description ...
- 【bzoj3560】DZY Loves Math V 欧拉函数
题目描述 给定n个正整数a1,a2,…,an,求 的值(答案模10^9+7). 输入 第一行一个正整数n. 接下来n行,每行一个正整数,分别为a1,a2,…,an. 输出 仅一行答案. 样例输入 3 ...
- 【BZOJ3960】DZY Loves Math V(数论)
题目: BZOJ3560 分析: orz跳瓜. 欧拉函数的公式: \[\phi(n)=n(\prod \frac{p_i-1}{p_i})\] 其中 \(p_i\) 取遍 \(n\) 的所有质因子. ...
- bzoj 3560 DZY Loves Math V - 线性筛 - 扩展欧几里得算法
给定n个正整数a1,a2,…,an,求 的值(答案模10^9+7). Input 第一行一个正整数n. 接下来n行,每行一个正整数,分别为a1,a2,…,an. Output 仅一行答案. Sampl ...
- bzoj DZY Loves Math V
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 509 Solved: 284[Submit][Status][Discuss] Descriptio ...
- DZY Loves Math系列
link 好久没写数学题了,再这样下去吃枣药丸啊. 找一套应该还比较有意思的数学题来做. [bzoj3309]DZY Loves Math 简单推一下. \[\sum_{i=1}^n\sum_{j=1 ...
随机推荐
- MySQL数据库服务器的架设
导读 MySQL数据库是Linux操作系统上用得最多的数据库系统,它可以非常方便的与其它服务器集成在一起,如Apache.Vsftpd.Postfix等.下面介绍RHEL 6平台MySQL数据库服务器 ...
- [codeforces 235]A. LCM Challenge
[codeforces 235]A. LCM Challenge 试题描述 Some days ago, I learned the concept of LCM (least common mult ...
- Windows2003操作系统SQL Server 2008安装图解(详细)
最近不少用户在windows2003 server 32位操作系统上安装SQL Server2008总是失败,出现大量错误.今天经过通过我反复测试安装,找出了一个便捷的安装方法,节省大家宝贵时间,具体 ...
- linux zookeeper 原理详解
http://cailin.iteye.com/blog/2014486 直接打开此链接即可 -------------------------------------------------- ...
- 【js】将table的每个td的内容自动赋值给其title属性
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- jquery 常用类别选择器
1.$('#showDiv'): id选择器,相当于javascript中的documentgetElementById("showDiv"); 2.$("onecla ...
- spring mvc 406 (Not Acceptable) json转换错误
spring mvc通过@RequestMapping("/register")和@ResponseBody返回json格式的字符串时出现如下异常: The resource id ...
- 关于Xcode6 Segue 的疑问,没有解决!
xcode6 的segue 变化了,如图 关于前3个选项,始终没有太明白,我试验结果如下,简单地把几个viewController连接起来时,无论用show,还是showdetail,还是Presen ...
- Java for LeetCode 179 Largest Number
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- Java for LeetCode 139 Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...