Cod sursa(job #2908851)

Utilizator ciobyCiobanu Vlasie cioby Data 6 iunie 2022 15:59:45
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <bits/stdc++.h>

using namespace std;
typedef unsigned long long ull;
ifstream fin("lgput.in");
ofstream fout("lgput.out");


ull a,b;
const long modulo=1999999973;

ull putere(ull a,ull b){

    ull p=1;
    while(b){
        if (b%2==1){
            p=p*a;
            p=p%modulo;
        }
        a=a*a;
        a=a%modulo;
        b/=2;
    }
    return p;
}

void solve(){

    fin>>a>>b;
    ///a la putere b
    ull ans=putere(a,b);
    fout<<ans;
}

int main(){
    solve();
}