Cod sursa(job #1604221)
| Utilizator | Data | 18 februarie 2016 03:00:02 | |
|---|---|---|---|
| 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 long get_pow(int n, int k)
{
long long aux;
if(k == 0)
return 1;
if( k % 2 == 0)
{
aux = get_pow(n, k/2);
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;
}
