Cod sursa(job #2460871)

Utilizator eduardandrei20Nechifor Eduard Andrei eduardandrei20 Data 24 septembrie 2019 17:07:06
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.42 kb
#include<iostream>
#include<fstream>
#define mod 1999999973
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");

int putere(int baza, int exp) {
	int rez = 1;

	while (exp > 0) {
		if (exp % 2 == 1) {
			rez = (1LL * rez*baza) % mod;
		}
		baza = (1LL*baza * baza)%mod;
		exp /= 2;
	}
	return rez;

}

int main()
{
	int n,p;
	in >> n>>p;
	out << putere(n, p);
	system("pause");
}