Cod sursa(job #2224817)

Utilizator cezarzbughinCezar Zbughin cezarzbughin Data 25 iulie 2018 11:35:18
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <bits/stdc++.h>

using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const int Mod = 1999999973;
int n,p;
int putere1(int b,int e)
{
    int r=1;
    for(;e;e>>=1)
    {
        if(e&1)r=1LL*r*b%Mod;
        b=1LL*b*b%Mod;
    }
    return r;
}
int putere2(int e)
{
    if(e==0)
        return 1;
    int r=putere2(e/2);
    r=1LL*r*r%Mod;
    if(e%2)r=1LL*r*n%Mod;
    return r;
}

int main()
{

    f>>n>>p;
    g<<putere1(n,p);
    return 0;
}