Cod sursa(job #1927106)

Utilizator GandalfTheWhiteGandalf the White GandalfTheWhite Data 14 martie 2017 22:17:40
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 kb
#include <cstdio>
#define M 1999999973
using namespace std;

int a,b,sol=1;
void Read(){

    freopen("lgput.in","r",stdin);
    scanf("%d%d",&a,&b);

}

void Pow(){

    int i;
    for (int i=0;(1<<i)<=b;++i)
        if ((1<<i)&b) sol=(sol*a)%M;
        else a=(a*a)%M;
}

void Write(){

    freopen("lgput.out","w",stdout);
    printf("%d",sol);
}
int main()
{
    Read();
    Pow();
    Write();
    return 0;
}