Cod sursa(job #1233662)

Utilizator aaron72Armand Ioan Anusca Popa aaron72 Data 25 septembrie 2014 20:36:16
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <fstream>

using namespace std;

int main()
{
    long long n,p,x;
    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
    fin>>n>>x;
    p=1;
    while(x!=0)
    {
        if (x%2==1)
        {
           x--;
           p=p*n;
        }
        n=n*n;
        x/=2;
    }
    if (p<1999999973)fout<<p<<"\n";
        else fout<<p-1999999973;
    fin.close();
    fout.close();
    return 0;
}