Cod sursa(job #1075306)
Utilizator | Data | 8 ianuarie 2014 20:35:41 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <fstream>
#define x 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n,k;
int pow(long long n,long long k)
{
int m=1;
while (k>1)
{
if(k%2==0)
{
n=(n*n)%x;
k=k/2;
}
else
{
m=(m*n)%x;
k--;
}
}
return((m*n)%x);
}
int main()
{
f >> n >>k;
g << (pow(n,k));
return 0;
}