Cod sursa(job #966721)
Utilizator | Spulber Iosif BlackElf | Data | 26 iunie 2013 15:18:33 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
int MOD = 1999999973;
int powMod (int n, int p)
{
if (p == 1)
return n % MOD;
if (p == 0)
return 1;
if (p % 2 == 0)
{
int aux = powMod (n, p/2) % MOD;
return aux * aux;
}
else
{
return (n * powMod (n, p-1)) % MOD;
}
}
int main ()
{
int n, p;
ifstream in ("lgput.in");
in >> n >> p;
ofstream out ("lgput.out");
out << powMod (n, p) << endl;
return 0;
}