1^5+2^5+3^5+……+n^5=
1*C(1,n)+31*C(2,n)+180*C(3,n)+390*C(4,n)+360*C(5,n)+120*C(6,n)
求1^5+2^5+3^5+…+n^5.
首先写出和式的前6项
即1^5=1 2^5=32 3^5=243 4^5=1024 5^5=3125 6^5=7776
再求出相邻两数之差,得
31 211 781 2101 4651
再次求出相邻两数之差,得
180 570 1320 2550
再次求,一直求到只剩一个数为止
390 750 1230
360 480
120
最后,取每一组数的第一个数(包括原数组),得:1,31,180,390,360,120
则1^5+2^5+3^5+……+n^5=
1*C(1,n)+31*C(2,n)+180*C(3,n)+390*C(4,n)+360*C(5,n)+120*C(6,n)
对于某一个p,有一种通法可以求1^p+2^p+3^p+...+n^p.
首先写出这个和式的前(p+1)项,
即
1^p 2^p 3^p 4^p …… (p+1)^p
然后求出相邻两数之差,得到的差有p个
再求出差的相邻两数之差,得到的差有(p-1)个
一直求下去,求到只剩一个差为止.
最后,包括原数组1^p 2^p 3^p 4^p …… (p+1)^p,一共有(p+1)组数.
取每组数的第一个数a1、a2、a3、a4……a(p+1)(注:这(p+1)个数的顺序为为求得差时的顺序.)
则1^p+2^p+3^p+...+n^p
1*C(1,n)+31*C(2,n)+180*C(3,n)+390*C(4,n)+360*C(5,n)+120*C(6,n)
求1^5+2^5+3^5+…+n^5.
首先写出和式的前6项
即1^5=1 2^5=32 3^5=243 4^5=1024 5^5=3125 6^5=7776
再求出相邻两数之差,得
31 211 781 2101 4651
再次求出相邻两数之差,得
180 570 1320 2550
再次求,一直求到只剩一个数为止
390 750 1230
360 480
120
最后,取每一组数的第一个数(包括原数组),得:1,31,180,390,360,120
则1^5+2^5+3^5+……+n^5=
1*C(1,n)+31*C(2,n)+180*C(3,n)+390*C(4,n)+360*C(5,n)+120*C(6,n)
对于某一个p,有一种通法可以求1^p+2^p+3^p+...+n^p.
首先写出这个和式的前(p+1)项,
即
1^p 2^p 3^p 4^p …… (p+1)^p
然后求出相邻两数之差,得到的差有p个
再求出差的相邻两数之差,得到的差有(p-1)个
一直求下去,求到只剩一个差为止.
最后,包括原数组1^p 2^p 3^p 4^p …… (p+1)^p,一共有(p+1)组数.
取每组数的第一个数a1、a2、a3、a4……a(p+1)(注:这(p+1)个数的顺序为为求得差时的顺序.)
则1^p+2^p+3^p+...+n^p
=a1*C(1,n)+a2*C(2,n)+a3*C(3,n)+…+a(p+1)*C(p+1,n)
实现代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
using namespace std;
const int maxn = 10000 + 5;
#define INF 0x3f3f3f3f
#define clr(x,y) memset(x,y,sizeof x )
typedef long long ll;
#define eps 10e-10
const int Mod = 10007;
typedef pair<int, int> P;
ll pow_mod(ll x,ll n,ll mod_val)
{
ll ans = 1;
ll t = x % mod_val;
while(n)
{
if(n & 1)
ans = ans * t % mod_val;
n >>= 1;
t = t * t % mod_val;
}
return ans;
}
ll C(ll n,ll m,ll p)
{
if(n < m)
return 0;
ll ans = 1;
for(ll i = 1; i <= m; i ++)
{
ans = ans * (n + 1 - i) % p;
ll x = pow_mod(i%p,p - 2,p);
ans = ans * x % p;
}
return ans;
}
ll Lucas(ll n,ll m,ll p)
{
if(m == 0)
return 1;
return C(n%p,m%p,p) * Lucas(n/p,m/p,p);
}
ll temp[maxn];
ll t[maxn];
ll work(ll n,ll times)
{
for(int i = 1; i <= times + 1; i ++)
{
temp[i] = pow_mod(i,times,Mod);
}
// cout << "YES" << endl;
t[1] = 1;
for(int i = 2; i <= times + 1; i ++)
{
for(int j = 1; j <= times; j ++)
{
temp[j] = temp[j + 1] - temp[j];
}
t[i] = temp[1];
}
// puts("YEs");
// for(int i = 1; i <= times + 1; i ++)
// cout << t[i] << " ";
// cout << endl;
ll ans = 0;
for(int i = 1; i <= times + 1; i ++)
{
ans += t[i] * Lucas(n,i,Mod) % Mod;
ans %= Mod;
}
// cout << n << " " << times << " " << ans << endl;
return ans;
}
ll a[maxn];
ll b[maxn];
int main()
{
// work(10,5);
int Tcase;
scanf("%d",&Tcase);
while(Tcase --)
{
ll n;
scanf("%I64d",&n);
for(int i = 0; i <= n; i ++)
{
scanf("%I64d",&a[i]),a[i] %= Mod;
}
ll k;
scanf("%I64d",&k);
// ll ans = a[0] % Mod * k % Mod;
ll ans = a[0] * k % Mod;
for(int i = 1; i <= n; i ++)
{
if(a[i])
ans = (ans + a[i] * work(k - 1,i) % Mod) % Mod;
// cout << a[i] << " " <<k - 1<< " " << i << " " << work(k - 1,i) << " " << a[i] * work(k ,i - 1) << endl;
}
printf("%I64d\n",ans);
}
return 0;
}