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