Cod sursa(job #2376504)

Utilizator davidbejenariu2David Bejenariu davidbejenariu2 Data 8 martie 2019 16:02:10
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>
#define MOD 1999999973
#define ull unsigned long long

using namespace std;

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

ull power( ull a, ull b )
{
    if ( b == 1 ) return a;

    ull p = power( a, b / 2 );
    p = ( p * p ) % MOD;

    if ( b % 2 != 0 )
        p = ( p * a ) % MOD;

    return p;
}

int main()
{
    ull a, b;

    fin >> a >> b;
    fin.close();

    fout << power( a, b );
    fout.close();

    return 0;
}