Cod sursa(job #947410)

Utilizator BitOneSAlexandru BitOne Data 7 mai 2013 13:17:46
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <cstdlib>
#include <fstream>

using namespace std;

const int MODULO = 1999999973;

inline int pow(int x, int n)
{
    int ans = 1;
    for(; n; n >>= 1)
    {
        if(n&1)
        {
            ans = (1LL * ans * x) % MODULO;
        }
        x = (1LL * x * x) % MODULO;
    }
    return ans;
}

int main()
{
    int x, n;

    ifstream in("lgput.in");
    ofstream out("lgput.out");

    in >> x >> n;
    out << pow(x, n) << '\n';

    return EXIT_SUCCESS;
}