eolymp
bolt
Try our new interface for solving problems
Problems

Modular Exponentiation

published at 1/25/24, 1:24:23 pm

include <bits/stdc++.h>

define ll long long

define ld long double

using namespace std; ll n, ans = 1; ll func(ll x, ll y, ll z){

if (y == 0)
    return 1 % z;

if (y % 2 == 1)
    return (func(x, y - 1, z) * x) % z;
else
    return (func((x * x) %z, y / 2 , z)) %z;

} int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m, k;
cin>>n>>m>>k;
cout<<func(n, m, k);

} //TECHNOBLADE NEVER DIES