Cod sursa(job #256073)

Utilizator AstronothingIulia Comsa Astronothing Data 11 februarie 2009 00:35:08
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include <fstream>

using namespace std;

const long c = 1999999973;

int main()
{
    ifstream f("lgput.in");
    ofstream f2("lgput.out");

    long long n,p,rez=1,aux;

    f>>n>>p;

    aux=n;

    for(int i=0; (1<<i)<=p ; i++)
    {
        if((p>>i)&1) rez = rez * aux;
        aux *= aux;
    }

    f2<<rez%c;

    f.close();
    f2.close();
    return 0;
}