Cod sursa(job #1909116)

Utilizator SCatalinStanciu Catalin SCatalin Data 7 martie 2017 11:40:17
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.36 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("lgput.in");
ofstream out("lgput.out");

typedef unsigned long long ULL;

ULL Putere(ULL x, ULL n)
{
	ULL p = 1 ;
	while (n > 0)
	{
		if (n%2)
		{
			p *= x;
			n-- ;
		}
		x*=x ;
		n/=2;
	}
	return p ;
}

int main()
{
    ULL a,b;
    in >> a >> b;
    out << Putere(a,b);
}