Pagini recente » Cod sursa (job #1749990) | Cod sursa (job #678220) | Cod sursa (job #409705) | Cod sursa (job #1522016) | Cod sursa (job #1723092)
#include<iostream>
#include<fstream>
using namespace std;
int exp(int x,int n)
{
if(n<0)
return -n;
else if(n==0)
return 1;
else if(n==1)
return x;
else if(n%2==0)
return exp(x*x,n/2);
else if(n%2==1)
return x*exp(x*x,(n-1)/2);
}
int exp2(int x,int n)
{int y;
if(n<0)
{
x=1/x;
n=-n;
}
if(n==0)return 1;
y=1;
while(n>1)
if(n%2==0)
{
x=x*x;
n=n/2;
}
else
{
y=y*x;
x=x*x;
n=(n-1)/2;
}
return x*y;
}
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
int x,n,y;
//cout<<"x=";cin>>x;
// cout<<x<<" la puterea n=";cin>>n;
f>>x>>n;
// cout<<exp(x,n)<<endl;
g<<exp2(x,n);
return 0;
}