HDU 5628 Clarke and math (Dirichlet卷积)
来源:互联网 发布:java制表符怎么用 编辑:程序博客网 时间:2024/06/07 17:13
题目链接:
HDU 5628
题意:
给你
求
题解:
g(i)=∑i1|i∑i2|i1∑i3|i2⋯∑ik|ik−1f(ik) =∑i1|i∑i2|i1∑i3|i2⋯∑ik|ik−1f(ik)∗h(ik).
化为
根据 狄利克雷卷积 满足交换律和结合律, 先利用快速幂
每次
嗯,感觉有点难解释。
就是两个函数
可以写成这样:
然后可以发现原式的一层就是一次
又因为狄利克雷卷积满足交换律和结合律,所以
然后快速幂套一个狄利克雷卷积就可以了。
总时间复杂度就是
但是刚才又想了一下。
发现了一个
我们可以考虑
可以发现,
然后我们发现
最后对于每一个
总时间复杂度就是
AC代码:
#include<bits/stdc++.h>using namespace std;typedef long long ll;const int mod =1e9+7;int n,k;ll f[100010];ll ans[100010];ll tmp[100010],x[100010];void dirichlet(ll *ans, ll *x){ memset(tmp,0,sizeof(tmp)); for(int i=1;i*i<=n;i++) { tmp[i*i] += ans[i]*x[i]%mod; if(tmp[i*i]>=mod) tmp[i*i]%=mod; for(int j=i+1;i*j<=n;j++) { tmp[i*j] += ans[i]*x[j]%mod; if(tmp[i*j]>=mod) tmp[i*j]%=mod; tmp[i*j] += ans[j]*x[i]%mod; if(tmp[i*j]>=mod) tmp[i*j]%=mod; } } for(int i=1;i<=n;i++) { ans[i] = tmp[i]; }}void qpower(){ while(k) { if(k&1) dirichlet(ans,x); k>>=1; dirichlet(x,x); } dirichlet(ans,f);//乘 f } void solve(){ for(int i=1;i<=n;i++) { scanf("%lld",&f[i]); ans[i] = 0; x[i] = 1; } ans[1] = 1; qpower();}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&k); solve(); for(int i=1;i<n;i++){ printf("%lld ",ans[i]); } printf("%lld\n",ans[n]); } return 0;}
- hdu 5628 Clarke and math Dirichlet卷积
- HDU 5628 Clarke and math (Dirichlet卷积)
- [Dirichlet卷积+快速幂]hdu 5628 Clarke and math
- [hdu5628]Clarke and math(dirichlet卷积)
- HDU-5628-Clarke-and-math-狄利克雷卷积
- HDU 5628 Clarke and math(Dirchlet卷积+快速幂)
- 狄利克雷卷积 【HDU5628】Clarke and math
- 【HDU5628】Clarke and math-狄利克雷卷积+快速幂
- 【狄利克雷卷积+快速幂】HDU5628[Clarke and math]题解
- HDU 5469 Clarke and problem (DP)
- HDU 5463 Clarke and minecraft(模拟)
- hdu 5562 Clarke and food(水)
- hdu 5565 Clarke and baton(水)
- HDU 5625 Clarke and chemistry(模拟)
- HDU 5625 Clarke and chemistry(水~)
- HDU 5627 Clarke and MST(贪心)
- HDU Clarke and points
- Clarke and MST HDU
- linux网络学习博客汇总
- python的sorted函数对字典按key排序和按value排序
- python第一天
- 动态规划算法
- python中的对象 一级对象?
- HDU 5628 Clarke and math (Dirichlet卷积)
- OpenGL ES for Android 笔记
- 关于“WireX Botnet”事件Android样本分析报告
- 2017 智慧树英语口语直通车答案单元测试答案
- javaweb之Servlet
- linux的文件及目录的默认权限umask值和chown改变用户属主及组和删除用户及-bash-4.1错误
- MongoDB Native Node.js Driver
- Lucky7 HDU
- 机器学习--SVM