Cod sursa(job #2228343)

Utilizator vlavricVictor Lavric vlavric Data 3 august 2018 14:15:05
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream f; ofstream g;

long long power(int x, int n)
{
	if (n == 0) return (1);
	else if (n == 1) return (x);
	else if (n % 2) power(x * x, (n - 1) / 2);
	else power(x * x, n / 2);
}

int	main(void)
{
	int n, m;

	f.open("lgput.in");
	f >> n >> m;
	f.close();
	g.open("lgput.out");
	g << power(n, m);
	g.close();
	return (0);
}