Cod sursa(job #1416589)
Utilizator | Data | 8 aprilie 2015 15:11:46 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
#define rest 1999999973
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int pow(int x, int n)
{
int p = 1;
while(n > 0)
{
if(n&1)
{
p *= x;
n--;
}
x = x * x;
n >>= 1;
}
return p;
}
int main()
{
int n, x ,rez;
fin >> n >> x;
rez = pow(n,x);
fout << rez%rest;
return 0;
}