Created
July 18, 2020 11:06
-
-
Save fxxntrbl/0d60fcecae7b5e6a1b374c0e1d51549d to your computer and use it in GitHub Desktop.
분할 정복 알고리즘 - (x^y)%m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
typedef long long int ll; | |
ll f (int x, ll y, int m) { | |
if (y == 0) return 1; | |
if (y == 1) return x % m; | |
if (y % 2 == 1) { | |
ll sib = f(x, y - 1, m) % m; | |
return ((sib % m) * (x % m)) % m; | |
} | |
else { | |
ll al = f (x, y/2, m) % m; | |
return ((al % m) * (al % m)) % m; | |
} | |
} | |
int main () { | |
int s = (1 << 27) + 7; | |
ll ib = (1LL << 62) + 985; | |
int al = (1 << 28) + 879; | |
cout << f (s, ib, al); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment