Mai intai trebuie sa te autentifici.
Cod sursa(job #1666318)
| Utilizator | Data | 27 martie 2016 21:32:18 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | c | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <stdio.h>
#include <stdlib.h>
#define N mod
long long n,p;
long long temp;
long long mod;
long long lgput(long long pt){
if(pt==1){
return n;
}
temp=lgput(pt/2)%mod;
temp=temp*temp%mod;
if(pt%2==1){
return temp*n;
}else{
return temp;
}
}
int main(){
freopen("modulo.in","r",stdin);
freopen("modulo.out","w",stdout);
scanf("%lld%lld%lld",&n,&p,&mod);
printf("%lld",lgput(p) % mod);
return 0;
}
