题意:求sigma(i*C(n, i)).
因为i*C(n, i) = i*n*(n-1)*...*(n-i+1)/i! = n*(n-1)*...*(n-2+1)/(i-1)! = (n-i+1)*C(n, i-1),
所以(i-1)*C(n,i-1)+i*C(n, i) = n*C(n, i-1),所以这个求和式的没两项都能合并,提出一个
n的公约数后,最后就是n*[C(n,0)+C(n,2)+C(n,4)+...] = n*2^(n-1).奇偶的情况是一样
的都是这个结果.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
using namespace std;
const long long mod = 1e9+7;
long long n;
long long qpow (long long a, long long b) {
if (b == 0)
return 1;
long long ans = qpow (a, b>>1);
ans = ans*ans % mod;
if (b&1) ans = ans*a%mod;
return ans;
}
int main () {
int t, kase = 0;
cin >> t;
while (t--) {
cin >> n;
printf ("Case #%d: ", ++kase);
cout << (n*qpow (2, n-1))%mod << endl;
}
return 0;
}