Cod sursa(job #2262512)

Utilizator vlad_schillerSchiller Vlad Radu vlad_schiller Data 17 octombrie 2018 15:41:27
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;

ifstream f("lgput.in");
ofstream g("lgput.out");
unsigned long long int s=1,n,p;

unsigned long long int logp(int b,int exp)
{
    if(!exp)
        return 1;
    if(exp%2==1)
        return (b*logp(b,exp-1))%mod;
    else
        return logp((b*b)%mod,exp/2);
}

int main()
{
    f>>n>>p;
    g<<logp(n,p);
    return 0;
}