Cod sursa(job #1364717)
| Utilizator | Data | 27 februarie 2015 19:53:45 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <fstream>
using namespace std;
ifstream fin("modulo.in");
ofstream fout("modulo.out");
const int MOD = 1999999973;
int N, P, C;
int lgput(int N, int P)
{
long long sol;
if (P == 0)
return 1;
sol = lgput(N, P / 2);
sol = (sol * sol) % MOD;
if (P % 2 == 1)
sol = (sol * N) % MOD;
return sol;
}
int main()
{
fin >> N >> P;
fout << lgput(N, P) << '\n';
fin.close();
fout.close();
return 0;
}
