Tuesday, 5 January 2016

UVa 10843 - Anne’s game

//\\__ hr1212 __//\\

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;

#define si(a) scanf("%lld",&a)
#define sii(a,b) scanf("%lld %lld",&a,&b)
#define siii(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 2000000011

ll n,m,dp[MAX];

ll pw(ll x,ll y){
    ll res=1;
    if(x==1)
        return res;
    while(y){
        if(y&1){
            res=(res%MOD*x%MOD)%MOD;
            y--;
        }
        else{
            x=(x%MOD*x%MOD)%MOD;
            y>>=1;
        }
    }
    return res;
}

int main(){
    ll r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
    ll ans=0;string p;

    si(t);
    f(i,0,t){
        si(n);
        printf("Case #%lld: %lld\n",i+1,pw(n,n-2));
    }

    return 0;
}

No comments:

Post a Comment