Cod sursa(job #2405705)

Utilizator S_AndyAndrei S S_Andy Data 14 aprilie 2019 19:32:21
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.29 kb
#include <fstream>

using namespace std;

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

#define R 1999999973

int main()
{
	unsigned long long n, p, s = 1;
	for (fin >> n >> p; p; p >>= 1) {
		if (p % 2 == 1) {
			s = (s * n) % R;
		}
		n = (n * n) % R;
	}
	fout << s;
}