hdu 5628 Clarke and math Dirichlet卷积
来源:互联网 发布:百度网络存在安全隐患 编辑:程序博客网 时间:2024/06/15 03:32
设f,g为两个数论函数,那么规定 (f∗g)(n)=∑d|n f(d)g(n/d)为f,g的Dirichlet卷积
该运算满足 交换律、结合律、分配律。
并且存在一个幺元e,使得e*f = f。 当i = 1 时 e[i] = 1,i != 1 时 e[i] = 0;
另函数 h[i] 恒等于 1.
g(i)=∑i1∣i∑i2∣i1∑i3∣i2⋯∑ik∣ik−1f(ik) = ∑i1∣i∑i2∣i1∑i3∣i2⋯∑ik∣ik−1f(ik) *h(ik) .
化为Dirichlet卷积形式,g(i) = (f*h^k)(i)
由于满足交换律, 先利用快速幂h^k。最后再拿h^k的结果与f卷积(注意,两个函数卷积的结果是函数,而不是值)
每次Dirichlet卷积的 复杂度为 O(n*logn),进行logk次卷积计算,单组复杂度O(n*logn*logk).
/************************************************************************* > File Name: hdu5628.cpp > Author: TechMonster > Mail: 928221136@qq.com > Created Time: 三 7/13 16:20:40 2016 ************************************************************************/#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;#define MS(x,y) memset(x,y,sizeof(x))typedef long long LL;const int N = 100010;const LL M = 1e9+7;template <class T1, class T2>inline void gadd(T1 &a, T2 b) {a += b;if(a > M) a%= M;}int n,k;LL f[N],ans[N],tem[N],x[N];void Dirichlet(LL *ans, LL *x)//Dirichlet卷积{MS(tem,0);for(int i = 1; i*i <= n; ++i){gadd(tem[i*i],ans[i]*x[i]%M);for(int j = i+1; j*i <= n; ++j){gadd(tem[i*j],ans[i]*x[j]%M);gadd(tem[i*j],ans[j]*x[i]%M);}}for(int i = 1; i <= n; ++i) ans[i] = tem[i];}void calc(){while(k) //快速幂{if(k&1) Dirichlet(ans,x);Dirichlet(x,x);k>>=1;}Dirichlet(ans,f); //乘f}void solve(){scanf("%d%d",&n,&k);for(int i = 1; i <= n; ++i){scanf("%lld",&f[i]);ans[i] = 0; x[i] = 1;//初始ans为幺元,x为恒等于1的函数}ans[1] = 1;calc();for(int i = 1; i < n; ++i) printf("%lld ",ans[i]);printf("%lld\n",ans[n]);}int main(){int T;scanf("%d",&T);while(T--)solve();return 0;}
2 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 Clarke and points
- Clarke and MST HDU
- HDU 5463 Clarke and minecraft
- HDU 5465 Clarke and puzzle
- HDU 5463 Clarke and minecraft
- HDU 5463 Clarke and minecraft
- HDU 5464:Clarke and problem
- HDU 5463Clarke and minecraft
- HDU 5465 Clarke and puzzle
- ubuntu详细教程[软件安装,命令大全,常用快捷键]
- 利用ppa安装ffmpeg, ubuntu14.04
- Android开发中高效的数据结构用SparseArray代替HashMap
- python 学习
- Jedis使用总结【pipeline】【分布式的id生成器】【分布式锁【watch】【multi】】【redis分布式】
- hdu 5628 Clarke and math Dirichlet卷积
- hibernate代码生成工具 转换工具 自动生成工具
- kubectl yaml/json参数设置
- scala操作数据库语句
- wait()、notify()和notifyAll()是 Object类 中的方法
- c#初学-多线程中lock用法的经典实例
- 最小生成树Prim算法
- 剑指offer系列-T24_1二叉树后序排序递归实现
- BZOJ3252 攻略