Cod sursa(job #1134108)
Utilizator | Data | 5 martie 2014 23:23:15 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include<fstream>
#include<cmath>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
unsigned long long n,p;
unsigned long long putere(int a,int k)
{
unsigned long long aux,sol;
aux=a;
sol=1;
while(k)
{
if(k%2==1)
sol=(sol%1999999973)*(aux%1999999973);
aux=(aux%1999999973)*(aux%1999999973);k/=2;
}
return sol%1999999973;
}
int main()
{
unsigned long long sol;
f>>n>>p;
sol=putere(n,p);g<<sol<<'\n';
return 0;
}