Cod sursa(job #2351928)

Utilizator _paulPaul Tanasa _paul Data 22 februarie 2019 20:19:53
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>

using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");

#define mod 1999999973

int main()
{
    long long x, rez = 1;
    int n, m;

    fin >> x >> n;
    for(m = 1; m <= n; m *= 2)
    {

        if( ( n & m ) != 0 )
            rez = 1ll* rez * x % mod;

        x = 1ll* x * x % mod;

    }

    fout << rez;

    return 0;

}