Cod sursa(job #1169721)

Utilizator hopingsteamMatraguna Mihai-Alexandru hopingsteam Data 11 aprilie 2014 22:07:29
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.53 kb
#include    <fstream>
using namespace std;

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

int a, b;
int mod = 1999999973;  

void solve(int a, int b)
{
    //fdeb << "a: " << a << " b: " << b << "\n";
    long long x, y = 1;
    x = a;
    for(int i = 0; (1 << i) <= b; i++)
    {
        if(((1 << i) & b) > 0)
            y = (y * x) % mod;
        x = (x * x) % mod;
    }
    //fdeb << y;
    fout << y;
}

void read()
{
    fin >> a >> b;
    solve(a, b);
}

int main()
{
    read();
    return 0;
}