Cod sursa(job #2721495)

Utilizator Victor2006Nicola Victor-Teodor Victor2006 Data 11 martie 2021 21:05:26
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.48 kb
#include <fstream>
#define MOD 1999999973

using namespace std;

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

int put( unsigned int a, unsigned int b ) {
    unsigned int ans = a;
    while ( b > 1 ) {
        if ( b % 2 == 1 ) {
            ans = ( ans * a ) % MOD;
        }
        ans = ( ans * ans ) % MOD;
        b /= 2;
    }
    return ans;
}

int main() {
    unsigned int a, b;
    fin >> a >> b;
    fout << put( a, b ) << "\n";
    return 0;
}