Rhezo likes numbers of the form . But computing , for any 2 numbers A and B is a hard task for him. He would like you to help him out with this.
Example:
Input: a = 4, b = "3"
Output: 64
Approach
C++
#include <bits/stdc++.h>using namespace std;const int mod = 1e9 + 7;long long exponention(long long x, long long n){long long res = 1;while (n > 0){if (n % 2 == 1)res = (res * x) % mod;x = (x * x) % mod;n = n / 2;}return res % mod;}int main(){long long a = 4;string b = "3";long long x = b.length();long long val = 0;for (int i = 0; i < x; i++){val = (val * 10 + b[i] - '0') % (mod - 1);}cout << exponention(a, val) % mod << "\n";return 0;}
No comments:
Post a Comment