SHARE
TWEET
Exponentiation by squaring
a guest
May 23rd, 2012
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- long long power(long long x, long long n)
- {
- if(n == 0)
- return 1;
- if(n % 2) // n is odd
- return (x * power(x, n - 1)) % Q;
- else // n is even
- {
- int a = power(x, n / 2);
- return (a * a) % Q;
- }
- }
RAW Paste Data

