写的话就是排列组合。。。但能化简。。。ΣC(n,i)*C(i,1) 化简为n*2^(n-1) ;
#include <iostream> #include <cstdio> #include <sstream> #include <cstring> #include <map> #include <set> #include <vector> #include <stack> #include <queue> #include <algorithm> #include <cmath> #define MOD 1000000007 #define LL long long #define ULL unsigned long long #define Pair pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define _ ios_base::sync_with_stdio(0),cin.tie(0) //freopen("1.txt", "r", stdin); using namespace std; const int maxn = 1000000, INF = 0x7fffffff; LL down[maxn], up[maxn]; LL qpow(LL a, LL b) { LL res = 1; while(b) { if(b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } // //void init() //{ // up[0] = 1; // down[0] = 1; // for(int i=1; i<maxn; i++) // { // up[i] = up[i-1] * i % MOD; // down[i] = qpow(up[i], MOD - 2); // } //} // //LL C(LL n, LL m) //{ // return up[n] * down[m] % MOD * down[n-m] % MOD; //} int main() { int T, kase = 0; // init(); cin>> T; while(T--) { LL n, res = 0, m; cin>> n; printf("Case #%d: %lld\n",++kase, n * qpow(2, n-1) % MOD); // cout<< C(n, m) <<endl; } return 0; }
原文地址:https://www.cnblogs.com/WTSRUVF/p/9319855.html
时间: 2024-10-08 22:44:45