Cod sursa(job #1229561)
Utilizator | Data | 17 septembrie 2014 18:17:26 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.37 kb |
#include <fstream>
using namespace std;
int main()
{
int n,p,x;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
fin>>n>>x;
p=1;
while(x!=0)
{
if (x%2==1)
{
p=p*n;
x--;
}
n=n*n;
x/=2;
}
fout<<p<<"\n";
fin.close();
fout.close();
return 0;
}