Cod sursa(job #1356953)

Utilizator Pintilie_AndreiFII-Pintilie Andrei Pintilie_Andrei Data 23 februarie 2015 17:50:57
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;

int main()
{
    ifstream fin("lgput.in");
    ofstream fout("lgput.out");
    long long n,p,sol;
    fin>>n>>p;
    sol=1;
    while(p>0)
    {
        if(p&1)
        {
            p--;
            sol=(n*sol)% mod;
        }
        n=(n*n)%mod;
        p>>=1;
    }
    fout<<sol;

    return 0;
}