Cod sursa(job #146676)

Utilizator igorPirnau Igor igor Data 1 martie 2008 23:30:56
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 kb
#include<fstream.h>

#define rest 1999999973

ifstream f("lgput.in");
ofstream g("lgput.out");

long long res, n, p;

int main()
{
    f>>n>>p;
    res=1;
    while(n){
        if( n&1 ){
            res=(res*p)%rest;
            n--;
        }
        p=(p*p)%rest;
        n<<=1;
    }

    g<<res<<'\n';
    g.close();
    return 0;
}