Author : Dipu Kumar Mohanto
CSE, Batch - 6
BRUR.
Problem Statement : 10843 - Anne's game
Source : UVA Online Judge
Category : Graph Theory
Algorithm : Cayley's Formula
Verdict : Accepted
- #include "bits/stdc++.h"
-
- using namespace std;
-
- #define ll long long
- #define MOD 2000000011
-
- inline ll bigMod(ll a, ll b)
- {
- if (b == 0) return 1;
- if (b & 1) return (a % MOD * bigMod(a, b-1)) % MOD;
- ll ret = bigMod(a, b>>1);
- return (ret % MOD * ret % MOD) % MOD;
- }
-
- int main()
- {
- int tc;
- cin >> tc;
- for (int tcase = 1; tcase <= tc; tcase++)
- {
- ll n;
- cin >> n;
- cout << "Case #" << tcase << ": ";
- if (n <= 2)
- {
- cout << 1 << endl;
- continue;
- }
- ll tpic = bigMod(n, n-2);
- cout << tpic << endl;
- }
- }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.