Cod sursa(job #693299)

Utilizator alexapoApostol Alexandru Ionut alexapo Data 27 februarie 2012 11:38:44
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <fstream>
#include <cmath>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n,p,pa,ni;
int main()
{
    f>>n>>p;
    pa=2;
    ni=n;
    n=pow(n,2);
    while(pa*2<=p)
    {
        n=pow(n,2);
        pa=pa*2;
    }

    while(pa<p)
    n=n*ni,pa++;
    g<<n%1999999973<<'\n';
    f.close();
    g.close();
    return 0;
}