Cod sursa(job #1318959)

Utilizator TomescuAngeloTomescu Angelo TomescuAngelo Data 16 ianuarie 2015 15:19:08
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.39 kb
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
    long long N,P,a,M,y,x,i;
    fin>>N>>P;
    M=1999999973;
    x=N%M;
    y=1;
    while(P!=0)
    {
        if(P%2==0)
        {
            y=(y*x)%M;
        }
        x=x*x;
        P=P/2;
    }
    fout<<y;
    fin.close();
    fout.close();
    return 0;
}