Cod sursa(job #2048246)

Utilizator marvelousMarvelous marvelous Data 25 octombrie 2017 21:02:08
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include <fstream>

using namespace std;

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

int p;
long long ans = 1, n;
const int MOD = 1999999973;

int main()
{
    F >> n >> p;
    for( int i = 0; ( 1 << i ) <= p; ++ i )
    {
        if( ( ( 1 << i ) & p ) ) ans = 1LL * (n % MOD) * ans;
        ans %= MOD;
        n = 1LL * n * n;
    }
    G << ans;
    return 0;
}