bzoj DZY Loves Math V
Time Limit: 10 Sec Memory Limit: 256 MB
Submit: 509 Solved: 284
[Submit][Status][Discuss]
Description
给定n个正整数a1,a2,…,an,求
的值(答案模10^9+7)。
Input
Output
Sample Input
6
10
15
Sample Output
HINT
1<=n<=10^5,1<=ai<=10^7。共3组数据。
Source
#include<bits/stdc++.h>
#define ll long long
#define maxn 100005
#define maxm 10000000
#define ha 1000000007
#define pb push_back
using namespace std;
vector<int> g[maxn*];
//g[i]存第i个出现的质因子的指数集合
int cnt=,n,m,dy[maxm+];
int ans=,now,mx[maxn*];
int mul[maxn]; inline int ksm(int x,int y){
int an=;
for(;y;y>>=,x=x*(ll)x%ha) if(y&) an=an*(ll)x%ha;
return an;
} inline void dvd(){
//质因数分解预处理出每个质因子有的指数集合
//dy[i]表示i这个质因子是第几个出现的
m=sqrt(now+0.5);
int c;
for(int i=;i<=m;i++) if(!(now%i)){
c=;
if(!dy[i]) dy[i]=++cnt;
while(!(now%i)) c++,now/=i;
g[dy[i]].pb(c),mx[dy[i]]=max(mx[dy[i]],c); if(now==) break;
} if(now!=){
if(!dy[now]) dy[now]=++cnt;
g[dy[now]].pb(),mx[dy[now]]=max(mx[dy[now]],);
}
} inline void solve(int x){
int tot=,dig=,pos=dy[x];
mul[]=;
//预处理等比数列前缀和
for(int i=;i<=mx[pos];i++){
dig=dig*(ll)x%ha;
mul[i]=mul[i-]+dig;
if(mul[i]>=ha) mul[i]-=ha;
} for(int i=g[pos].size()-;i>=;i--){
tot=tot*(ll)mul[g[pos][i]]%ha;
}
tot--;
if(tot<) tot+=ha;
tot=tot*(ll)(x-)%ha*(ll)ksm(x,ha-)%ha;
tot++; ans=ans*(ll)tot%ha;
} int main(){
// freopen("data.in","r",stdin);
// freopen("data.out","w",stdout); scanf("%d",&n);
while(n--){
scanf("%d",&now);
dvd();
} for(int i=;i<=maxm;i++) if(dy[i]) solve(i); printf("%d\n",ans);
return ;
}
bzoj DZY Loves Math V的更多相关文章
- 【BZOJ 3560】 3560: DZY Loves Math V (欧拉函数)
3560: DZY Loves Math V Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 241 Solved: 133 Description ...
- [BZOJ] DZY Loves Math 系列 I && II
为了让自己看起来有点事干 ,做个套题吧..不然老是东翻翻西翻翻也不知道在干嘛... \(\bf 3309: DZY \ Loves \ Math\) 令 \(h=f*\mu\) 很明显题目要求的就是\ ...
- bzoj 3560 DZY Loves Math V - 线性筛 - 扩展欧几里得算法
给定n个正整数a1,a2,…,an,求 的值(答案模10^9+7). Input 第一行一个正整数n. 接下来n行,每行一个正整数,分别为a1,a2,…,an. Output 仅一行答案. Sampl ...
- BZOJ3560 DZY Loves Math V 数论 快速幂
原文链接http://www.cnblogs.com/zhouzhendong/p/8111725.html UPD(2018-03-26):蒟蒻回来重新学数论了.更新了题解和代码.之前的怼到后面去了 ...
- BZOJ3560 : DZY Loves Math V
因为欧拉函数是非完全积性函数,所以可以考虑对每个数进行分解质因数,将每个质数的解乘起来即可. 对于一个质数$p$,设它在各个数中分别出现了$b_1,b_2,...b_n$次,那么由生成函数和欧拉函数的 ...
- BZOJ3560 DZY Loves Math V(欧拉函数)
对每个质因子分开计算再乘起来.使用类似生成函数的做法就很容易统计了. #include<iostream> #include<cstdio> #include<cmath ...
- BZOJ DZY Loves Math系列
⑤(BZOJ 3560) $\Sigma_{i_1|a_1}\Sigma_{i_2|a_2}\Sigma_{i_3|a_3}\Sigma_{i_4|a_4}...\Sigma_{i_n|a_n}\ph ...
- [BZOJ3560]DZY Loves Math V(欧拉函数)
https://www.cnblogs.com/zwfymqz/p/9332753.html 由于欧拉函数是积性函数,可以用乘法分配律变成对每个质因子分开算最后乘起来.再由欧拉函数公式和分配律发现就是 ...
- 【bzoj3560】DZY Loves Math V 欧拉函数
题目描述 给定n个正整数a1,a2,…,an,求 的值(答案模10^9+7). 输入 第一行一个正整数n. 接下来n行,每行一个正整数,分别为a1,a2,…,an. 输出 仅一行答案. 样例输入 3 ...
随机推荐
- 【BZOJ 3643】Phi的反函数 数搜索
这道题是典型的数搜索,讲究把数一层一层化小,而且还有最重要的大质数剪枝. #include <cstdio> #include <cmath> typedef long lon ...
- Working with large data sets in MySQL
What does working with large data sets in mySQL teach you ? Of course you have to learn a lot about ...
- mysql之蠕虫复制
蠕虫复制 蠕虫复制:从已有的数据表中获取数据,然后将数据进行新增操作,数据成倍(以指数形式)的增加. 根据已有表创建新表,即复制表结构,其基本语法为: create table + 表名 + like ...
- shell编程 if 注意事项
read -n 1 -p "Let's go(y or n):" if [ "$REPLY"x = "y"x -o "$REPLY ...
- JS模块化工具requirejs教程02
基本API require会定义三个变量:define,require,requirejs,其中require === requirejs,一般使用require更简短 define 从名字就可以看出 ...
- powercmd注册码
推荐一个很方便的软件:powercmd 用户名:nzone 注册码:PCMDA-86128-PCMDA-70594 . 下载地址网上很多: http://soft.hao123.com/soft/a ...
- cxf+spring发布webservice和调用
maven项目配置http://cxf.apache.org/docs/using-cxf-with-maven.html <properties> <cxf.version> ...
- concurrent
from concurrent.futures import ThreadPoolExecutor
- loggin
# 参考:https://www.cnblogs.com/DI-DIAO/p/8793136.html BASE_LOG_DIR = os.path.join(BASE_DIR, "log& ...
- python函数篇:名称空间、作用域和函数的嵌套
一.名称空间:(有3类) (1)内置名称空间(全局作用域) (2)全局名称空间(全局作用域) (3)局部名称空间(局部作用域) 关于名称空间的查询: x=1 def func(): print('fr ...