Cod sursa(job #1891277)

Utilizator AlexVulpoiuAlexandru Vulpoiu AlexVulpoiu Data 23 februarie 2017 21:14:31
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.37 kb
#include <cstdio>
using namespace std;
long long int n,p,k,x,mod;
int main()
{
    freopen("lgput.in","r",stdin);
    freopen("lgput.out","w",stdout);
    scanf("%lld%lld",&n,&p);
    x=n;
    k=1;
    mod=1999999973;
    while(p)
    {
        if(p%2==1)
            k=(k*x)%mod;
        x=(x*x)%mod;
        p/=2;
    }
    printf("%lld\n",k);
    return 0;
}