Cod sursa(job #189003)

Utilizator warcryAlin B warcry Data 11 mai 2008 14:05:39
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long pow(long x, long n);
int main()
{
 		int m,n;
 		fin>>m>>n;
 		fout<<pow(m,n);
 		return 0;
}
long pow(long x, long n)
{
    long result = 1;
    while ( n ) {
        if ( n & 1 ) {
            result = result * x;
            n = n-1;
        }
        x = x*x;
        n = n/2;
    }
    return result;
}