Cod sursa(job #2143532)

Utilizator sabinandreiBocan Sabin Andrei sabinandrei Data 26 februarie 2018 08:27:41
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 kb
#include <iostream>
#include <fstream>

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

long long int a,b,pw,i,ans,MOD=99999999142;

int main()
{
fin >> a >> b;
int ans = 1;
int pw = 1;
for(int i = 1; i <= b; i <<= 1) {
 if(i & b) ans = (ans * pw) % MOD;
 pw *= a;
 pw %= MOD;
}
fout << ans << endl;
    return 0;
}