Cod sursa(job #2199004)

Utilizator daniel.vbVasile Daniel daniel.vb Data 26 aprilie 2018 09:20:48
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 kb
#include <stdio.h>

#define R 1999999973

int main ()
{
    unsigned long long int n,p,m;
    scanf("%llu%llu",&n,&p);
    m=1;
    if(p==0)
        n=1;
    if(p>1)
    {
        while(p>=2)
        {
            if(p%2==1)
                m=m*n%R;
            n=n*n%R;
            p=p/2;
        }
        n=n*m%R;
    }
    printf("%llu\n",n);
}