Cod sursa(job #1150953)
Utilizator | Data | 23 martie 2014 19:00:47 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, p;
long long exp(int x, int y)
{
if (!y) return 1;
else
if (y % 2) return (x % MOD)*(exp(x, y-1) % MOD) % MOD;
else
{
long long p2;
p2 = exp(x, y/2) % MOD;
return p2 * p2;
}
}
int main()
{
fin>>n>>p;
fout<<exp(n, p)<<'\n';
fin.close();
fout.close();
return 0;
}