UVa 11609 Teams (組合數學)

來源:互聯網
上載者:User

11609 - Teams

Time limit: 1.000 seconds

http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=26 56

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 players to play, selects K (1 ≤ K ≤ N) players and make one of them as the captain for each phase of the game. Your task is simple, just find in how many ways a coach can select a team from his N players. Remember that, teams with same players but having different captain are considered as different team.

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                            
3
Case #1: 1
Case #2: 4
Case #3: 12

思路:易得結果為

完整代碼:

/*0.012s*/  #include <cstdio>#define ll long longconst int mod = 1000000007;  ll pow(ll a, ll b) ///a^b % mod{    ll r = 1, base = a;    while (b)    {        if (b & 1)            r = r * base % mod;        base = base * base % mod;        b >>= 1;    }    return r;}  int main(void){    int T, CASE = 0;    ll n;    scanf("%d", &T);    while (T--)    {        scanf("%lld", &n);        printf("Case #%d: %lld\n", ++CASE, (n * pow(2, n - 1)) % mod);    }}

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.