UVa : 11609 (Teams)



// http://uva.onlinejudge.org/external/116/11609.html
// Runtime: 0.012s
// Tag: bigMod

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>

#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL long long

#define For(i, a, b) for ( int i = (a); i < (b); i++ )
#define Forv(i, sz) for ( size_t i = 0; i < sz.size (); i++ )
#define Set(a, s) memset (a, s, sizeof (a))

using namespace std;

#define MOD 1000000007

LL bigMod (LL b, LL p)
{
    if ( p == 0 ) return 1;
    if ( p == 1 ) return b;

    if ( p % 2 == 0 ) {
        LL x = bigMod (b, p / 2) % MOD;
        return (x * x) % MOD;
    }
    else
        return (bigMod (b, p - 1) % MOD) * (b % MOD);
}


int main ()
{
    int testCase;
    scanf ("%d", &testCase);
    int cases = 0;

    while ( testCase-- ) {
        int n;
        scanf ("%d", &n);

        printf ("Case #%d: ", ++cases);
        cout << ((bigMod (2, n - 1) * (n % MOD)) % MOD) << endl;
    }

	return 0;
}

// @END_OF_SOURCE_CODE
Advertisements

One thought on “UVa : 11609 (Teams)

  1. suppose, there are 10 members and you are one of them
    and you are always the team leader
    now how many ways others can be selected?

    ans is: 2 to power 9
    000000000
    000000001
    000000010
    ….
    ….
    ….
    111111111

    ‘1’ means that member is selected
    when its 000000000 then it means, you are the only selected member

    finally, every members have equal rights to be the team leader besides you 😛
    so output: 2^9 * 10
    general formula: if total member N, output: (2 ^ (N- 1)) * N

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s