Cod sursa(job #947138)
Utilizator | Data | 6 mai 2013 19:44:03 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long n,x=1;
int p;
int pow(int n, int p){
if(p==0)
return n;
if(p&1==1){
p--;
x=(x*n)%1999999973;
return pow(n,p);
}
else{
p/=2;
n*=n;
return pow(n,p);
}
}
int main()
{
f>>n>>p;
g<<pow(n,p);
}