Cod sursa(job #584235)
Utilizator | Data | 24 aprilie 2011 18:53:19 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.35 kb |
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
double x;
int n;
double putere()
{
double p = 1 ;
while (n > 0)
{
if (n & 1) // n este impar
{
p *= x;
n-- ;
}
x = x * x ;
n >>= 1 ; // sau n = n / 2
}
return p;
}
int main()
{int a;
f>>x>>n;
a=putere();
g<<a%1999999973;
return 0;
}