对每个质因子分开计算再乘起来。使用类似生成函数的做法就很容易统计了。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
int x=,f=;char c=getchar();
while (c<''||c>'') {if (c=='-') f=-;c=getchar();}
while (c>=''&&c<='') x=(x<<)+(x<<)+(c^),c=getchar();
return x*f;
}
#define N 100010
#define M 10000010
#define P 1000000007
int n,a[N],prime[M>>],id[M],v[M>>],inv[M],cnt=,ans=;
bool flag[M];
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj3560.in","r",stdin);
freopen("bzoj3560.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
n=read();
for (int i=;i<=n;i++) a[i]=read();
inv[]=;
for (int i=;i<=M-;i++)
{
inv[i]=P-1ll*(P/i)*inv[P%i]%P;
if (!flag[i]) prime[++cnt]=i,id[i]=cnt,v[cnt]=;
for (int j=;j<=cnt&&prime[j]*i<=M-;j++)
{
flag[prime[j]*i]=;
if (i%prime[j]==) break;
}
}
for (int i=;i<=n;i++)
{
int x=a[i];
for (int j=;flag[x];j++)
if (x%prime[j]==)
{
int tot=;
while (x%prime[j]==) tot=(1ll*tot*prime[j]+)%P,x/=prime[j];
v[j]=1ll*v[j]*tot%P;
}
if (x>) v[id[x]]=1ll*v[id[x]]*(x+)%P;
}
for (int i=;i<=cnt;i++)
if (v[i]>) ans=1ll*ans*(1ll*(v[i]-)*(prime[i]-)%P*inv[prime[i]]%P+)%P;
cout<<ans;
return ;
}

BZOJ3560 DZY Loves Math V(欧拉函数)的更多相关文章

  1. [BZOJ3560]DZY Loves Math V(欧拉函数)

    https://www.cnblogs.com/zwfymqz/p/9332753.html 由于欧拉函数是积性函数,可以用乘法分配律变成对每个质因子分开算最后乘起来.再由欧拉函数公式和分配律发现就是 ...

  2. 【bzoj3560】DZY Loves Math V 欧拉函数

    题目描述 给定n个正整数a1,a2,…,an,求 的值(答案模10^9+7). 输入 第一行一个正整数n. 接下来n行,每行一个正整数,分别为a1,a2,…,an. 输出 仅一行答案. 样例输入 3 ...

  3. BZOJ3560 : DZY Loves Math V

    因为欧拉函数是非完全积性函数,所以可以考虑对每个数进行分解质因数,将每个质数的解乘起来即可. 对于一个质数$p$,设它在各个数中分别出现了$b_1,b_2,...b_n$次,那么由生成函数和欧拉函数的 ...

  4. BZOJ3560 DZY Loves Math V 数论 快速幂

    原文链接http://www.cnblogs.com/zhouzhendong/p/8111725.html UPD(2018-03-26):蒟蒻回来重新学数论了.更新了题解和代码.之前的怼到后面去了 ...

  5. 【BZOJ 3560】 3560: DZY Loves Math V (欧拉函数)

    3560: DZY Loves Math V Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 241  Solved: 133 Description ...

  6. 【BZOJ3960】DZY Loves Math V(数论)

    题目: BZOJ3560 分析: orz跳瓜. 欧拉函数的公式: \[\phi(n)=n(\prod \frac{p_i-1}{p_i})\] 其中 \(p_i\) 取遍 \(n\) 的所有质因子. ...

  7. [BZOJ4026]dC Loves Number Theory 欧拉函数+线段树

    链接 题意:给定长度为 \(n\) 的序列 A,每次求区间 \([l,r]\) 的乘积的欧拉函数 题解 考虑离线怎么搞,将询问按右端点排序,然后按顺序扫这个序列 对于每个 \(A_i\) ,枚举它的质 ...

  8. bzoj 3560 DZY Loves Math V - 线性筛 - 扩展欧几里得算法

    给定n个正整数a1,a2,…,an,求 的值(答案模10^9+7). Input 第一行一个正整数n. 接下来n行,每行一个正整数,分别为a1,a2,…,an. Output 仅一行答案. Sampl ...

  9. bzoj DZY Loves Math V

    Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 509  Solved: 284[Submit][Status][Discuss] Descriptio ...

随机推荐

  1. 成都Uber优步司机奖励政策(4月10日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  2. CF 868 F. Yet Another Minimization Problem

    F. Yet Another Minimization Problem http://codeforces.com/contest/868/problem/F 题意: 给定一个长度为n的序列.你需要将 ...

  3. python3.0 day02 列表、元组 、字典、字符串操作

    1.列表.元组操作 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作,类似于其他语言中的数组. 定义列表 names = ['Lioa',"Tenglan ...

  4. scala : 类型与类

    scala类型系统:1) 类型与类 在Java里,一直到jdk1.5之前,我们说一个对象的类型(type),都与它的class是一一映射的,通过获取它们的class对象,比如 String.class ...

  5. Javascript库,前端框架(UI框架),模板引擎

    JavaScript库:JQuery,undoscore,Zepto 纯Javascript语言封装, 前端框架(UI框架):Bootstrap,Foundation,Semantic UI,Pure ...

  6. My status

    I haven‘t any one who is strong relationship with me. My skill is normal. I'm not interesting in neg ...

  7. Firefox开发

    官方文档 First extension 目录结构 ➜ firefox tree . └── borderify └── manifest.json // 必须 directory, files ma ...

  8. Tempter of the Bone HDU 1010(DFS+剪枝)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

  9. 通俗理解Hilbert希尔伯特空间

    作者:qang pan 链接:https://www.zhihu.com/question/19967778/answer/28403912 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权, ...

  10. 记录 C++ STL 中 一些好用的函数--持续更新 (for_each,transform,count_if,find_if)

    在日常的编程中,有这么几种操作还是比较常见的: 把一组数据都赋值成一个数,在一组数据中查找一个数,统计一组数据中符合条件的数等等. 一般的写法可以用循环,没有什么是循环不能搞定的.假如在这里怎么用介绍 ...