Cod sursa(job #1604220)
| Utilizator | Data | 18 februarie 2016 02:54:48 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const long int m = 1999999973;
long int get_pow(int n, int k)
{
long long aux;
if(k == 0)
return 1;
if( k % 2 == 0)
{
aux = get_pow(n, k/2)%m;
aux = (aux *aux)%m;
return aux;
}
else
{
aux = get_pow(n,k-1)%m;
aux *= n%m;
return aux;
}
}
int main()
{
int n, k;
fin >> n >> k ;
fout << get_pow(n, k);
return 0;
}
