Teams 解題報告(組合數學)
Problem E
Teams
Input: Standard Input
Output: Standard Output
In a galaxy far far away there is an ancient game played among the planets. The specialty of the game is that there is no limitation on the number of players in each team, as long as there is a captain in the team. (The game is totally strategic, so sometimes less player increases the chance to win). So the coaches who have a total of N
Input
The first line of input contains the number of test cases T ≤ 500. Then each of the next T lines contains the value of N (1 ≤ N ≤ 10^9), the number of players the coach has.
Output
For each line of input output the case number, then the number of ways teams can be selected. You should output the result modulo 1000000007.
For exact formatting, see the sample input and output.
Sample Input Output for Sample Input
3 1 2 |
Case #1: 1 Case #2: 4 Case #3: 12 |
Problem Setter: Towhidul Islam Talukdar
Special Thanks: Md. Arifuzzaman Arif
解題報告:大水題。先從n個人中選出冠軍,一共n種選法。其他人在或者不在,都是兩種情況,一共2^(n-1)種情況。二分快速冪一下。程式碼如下:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
typedef long long LL;
LL powMod(LL a, LL b)
{
LL res=1;
while(b)
{
if(b&1)
res = res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
int cas=1;
void work()
{
int n;
scanf("%d",&n);
printf("Case #%d: %lld\n", cas++, powMod(2, n-1)*n%mod);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
work();
}