Cod sursa(job #2057782)
| Utilizator | Data | 4 noiembrie 2017 19:12:21 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int exp_log (int n, int p)
{
if (p == 0)
return 1;
if (p == 1)
return n;
if (p%2 == 0)
return (exp_log(n*n, p/2))%1999999973;
if (p%2 == 1)
return (n*exp_log(n*n, (p-1)/2))%1999999973;
}
int main()
{
int N, P;
fin>>N>>P;
fout<<exp_log(N, P)%1999999973;
}
