Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <cstdio>
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- bool isOdd(int num) {
- return num % 2 == 1;
- }
- int recursion(int x, int n, int m) {
- if (m < 0)
- return 0;
- if (n == 0) {
- return 1;
- }
- if (n > 0 && !isOdd(n)) {
- return ((x % m) * recursion(x, n - 1, m)) % m;
- }
- if (n > 0 && isOdd(n)) {
- int f = recursion(x, n / 2, m);
- return (f * f) % m;
- }
- }
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment