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