Pagini recente » Cod sursa (job #639940) | Cod sursa (job #1354340) | Cod sursa (job #3030614) | Cod sursa (job #1001374) | Cod sursa (job #2057788)
#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()
{
long long n, p;
fin>>n>>p;
//fout<<exp_log(n, p);
if(p == 0)
fout<<1;
else
{
long long 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;
}
}