http://acm.hdu.edu.cn/showproblem.php?pid=5628php
Clarke is a patient with multiple personality disorder. One day, he turned into a mathematician, did a research on interesting things.
Suddenly he found a interesting formula. Given f(i),1≤i≤n, calculate
g(i)=∑i1∣i∑i2∣i1∑i3∣i2⋯∑ik∣ik−1f(ik) mod 1000000007(1≤i≤n)c++
The first line contains an integer T(1≤T≤5), the number of test cases.
For each test case, the first line contains two integers n,k(1≤n,k≤100000).
The second line contains n integers, the ith integer denotes f(i),0≤f(i)<109+7.spa
For each test case, print a line contained n integers, the ith integer represents g(i).rest
2
6 2
2 3 3 3 3 3
23 3
2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3code
2 7 7 15 7 23
2 9 9 24 9 39 9 50 24 39 9 102 9 39 39 90 9 102 9 102 39 39 9orm
dp
dp[i][j]表示第i位置,選擇了j個不一樣的因子以後,可以得到的權值是多少
ans[i]=sigma C(k,j)*dp[i][j]
爲何呢?
咱們考慮傳遞了k次的sigma,實際上就是在枚舉因子,在這個數據範圍內,最多枚舉20個不一樣的因子,並且因子顯然是不斷遞減的(固然,這句話沒什麼用
而後腦補腦補,這個就是對的了……blog
官方題解確實看不懂……
弱智選手並不會xx卷積……ip
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5+7; const int mod = 1e9+7; long long fac[maxn]; long long qpow(long long a,long long b) { long long ans=1;a%=mod; for(long long i=b;i;i>>=1,a=a*a%mod) if(i&1)ans=ans*a%mod; return ans; } long long C(long long n,long long m) { if(m>n||m<0)return 0; long long s1=fac[n],s2=fac[n-m]*fac[m]%mod; return s1*qpow(s2,mod-2)%mod; } int a[maxn]; int dp[maxn][22]; int K=20; int main() { fac[0]=1; for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod; int t; scanf("%d",&t); while(t--) { int n,m; memset(dp,0,sizeof(dp)); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) dp[i][0]=a[i]; for(int i=1;i<=n;i++) for(int j=i+i;j<=n;j+=i) for(int k=0;k<K;k++) dp[j][k+1]=(dp[j][k+1]+dp[i][k])%mod; for(int i=1;i<=n;i++) { int ans = 0; for(int j=0;j<=K;j++) ans=(ans+1ll*C(m,j)*dp[i][j])%mod; if(i==n)printf("%d",ans);else printf("%d ",ans); } printf("\n"); } }