Pagini recente » Cod sursa (job #1877356) | Cod sursa (job #479534) | Cod sursa (job #1419489) | Cod sursa (job #2447049) | Cod sursa (job #1006460)
#include <fstream>
using namespace std;
ifstream is("lgput.in");
ofstream os("lgput.out");
int ExponentiereRapida(int x,int n)
{
if ( n < 0 )
return ExponentiereRapida( 1/x,-n);
if ( n == 0 )
return 1;
if ( n == 1 )
return x;
if ( n % 2 == 0 )
return ExponentiereRapida( x*x, n/2 );
if ( n % 2 == 1 )
return x * ExponentiereRapida( x*x, (n-1)/2 );
}
int main()
{
long long r,n,p;
is >> n;
is >> p;
r = ExponentiereRapida(n,p) ;
os << r;
}