Cod sursa(job #2375367)

Utilizator BlkAlexAlex Negru BlkAlex Data 8 martie 2019 08:33:23
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <bits/stdc++.h>
#define MOD 1999999973

using namespace std;

long long x, n;

void dostuff(){
    cin >> x >> n; //x^n
}

long long mypow (long long x, long long n){
    if (n == 1){
        return x;
    }
    if (n == 0){
        return 1;
    }
    if (n%2){
        return (x*mypow(x*x%MOD, (n-1)/2))%MOD;
    } else {
        return (mypow(x*x%MOD, n/2))%MOD;
    }
}

int main()
{
    dostuff();
    cout << mypow (x, n);
    return 0;
}