Cod sursa(job #1755086)

Utilizator Harsan_SabinHarsan Sabin Harsan_Sabin Data 9 septembrie 2016 13:29:11
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <fstream>
#define Mod %1999999973

using namespace std;

ifstream cin("lgput.in");
ofstream cout("lgput.out");

typedef unsigned __int64 unt;

unt n,p;

unt PowLog(unt b,unt p)
{
    if(p==0)
        return 1;

    if(p==1)
        return b;

    if(p%2)
        return (b*PowLog(b*b Mod,(p-1)/2)) Mod;
    else
        return PowLog(b*b Mod,p/2) Mod;

}

int main()
{
    cin>>n>>p;
    cout<<PowLog(n,p);
    return 0;
}