链接
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2656
题解
a n s = ∑ i = 1 n i C n i = ∑ i = 1 n i n ! i ! ( n − i ) ! = n ( n − 1 ) ! ( i − 1 ) ! ( n − i ) ! = n ∑ i = 0 n − 1 C n − 1 i = n × 2 n ans=\sum_{i=1}^niC_{n}^i\\ =\sum_{i=1}^{n}i{n!\over i!(n-i)!}=n{(n-1)!\over (i-1)!(n-i)!}\\ =n\sum_{i=0}^{n-1}C_{n-1}^i\\ =n\times 2^n ans=i=1∑niCni=i=1∑nii!(n−i)!n!=n(i−1)!(n−i)!(n−1)!=ni=0∑n−1Cn−1i=n×2n
代码
//组合数
#include <bits/stdc++.h>
#define mod 1000000007ll
#define ll long long
using namespace std;
ll fastpow(ll a, ll b)
{
ll ans=1, t=a;
for(;b;b>>=1,t=t*t%mod)if(b&1)ans=ans*t%mod;
return ans;
}
int main()
{
ll ans, i, kase, T, n;
scanf("%lld",&T);
for(kase=1;kase<=T;kase++)
{
scanf("%lld",&n);
printf("Case #%lld: %lld\n",kase,n*fastpow(2,n-1)%mod);
}
return 0;
}