Cod sursa(job #2223419)
| Utilizator | Data | 20 iulie 2018 10:32:50 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <stdio.h>
#include <stdlib.h>
#define IMPART 1999999973
long long computePower(long long n,long long p){
if(p==1) return n;
else if(p%2==0) return (computePower((n*n)%IMPART,p/2))%IMPART;
else return (n*computePower((n*n)%IMPART,(p-1)/2))%IMPART;
}
int main()
{
FILE*fin,*fout;
fin = fopen("lgput.in" ,"r");
fout = fopen("lgput.out" ,"w");
long long n,p;
fscanf(fin, "%lld%lld" ,&n,&p);
fprintf(fout, "%lld\n" ,computePower(n,p));
fclose(fin);
fclose(fout);
return 0;
}
