Cod sursa(job #2173140)

Utilizator cubaLuceafarul cuba Data 15 martie 2018 20:53:11
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const int mod = 1999999973;
inline long long Ridica(long long x, long long n) {
    long long p = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            p = (1LL * p * x) % mod;
            n--;
        }
        x = (1LL * x * x) % mod;
        n = n / 2;
    }
    return p;
}
int main()
{
    long long x, n;
    f >> x >> n;
    g << Ridica(x, n);
    return 0;
}