Cod sursa(job #1655505)
| Utilizator | Data | 18 martie 2016 01:06:58 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <stdio.h>
#define MOD 1999999973
long long n,p;
long long exp (long long n,long long p)
{
if(p == 0)
return 1;
if(p == 1)
return n%MOD;
if(p % 2 == 0)
return (exp(n, p / 2) % MOD) * (exp(n, p / 2) % MOD);
else
return (exp(n, p / 2) % MOD)*(exp(n, p / 2) % MOD) * n % MOD;
}
using namespace std;
int main()
{
FILE *fin, *fout;
fin = fopen("lgput.in","r");
fout = fopen("lgput.out","w");
fscanf(fin, "%lld%lld", &n, &p);
fprintf(fout, "%lld", exp(n, p));
return 0;
}
