Pagini recente » Cod sursa (job #3165227) | Cod sursa (job #1426505) | Cod sursa (job #997221) | Cod sursa (job #1632723) | Cod sursa (job #2057786)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int exp_log (int n, int p)
{
if (p == 0)
return 1;
if (p == 1)
return n;
if (p%2 == 0)
return (exp_log(n*n, p/2));
if (p%2 == 1)
return (n*exp_log(n*n, (p-1)/2));
}
int main()
{
int n, p;
fin>>n>>p;
//fout<<exp_log(N, P);
if(p == 0)
fout<<1;
else
{
int x =1;
while(p>1)
{
if(p%2 == 0)
{
n = n*n;
p=p/2;
}
else
{
x = n*x;
n = n*n;
p = (p-1)/2;
}
}
fout<<x*n;
}
}