Cod sursa(job #936655)

Utilizator forgetHow Si Yu forget Data 8 aprilie 2013 04:46:41
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.29 kb
#include <fstream>
using namespace std;

int main() {
	ifstream fin("lgput.in");
	ofstream fout("lgput.out");
	const int mod = 1999999973;
	unsigned long long n, p, ans = 1;
	fin >> n >> p;

	while (p > 0) {
		if (p%2) ans = (ans*n)%mod;
		n = (n*n)%mod;
		p /= 2;
	}
	fout << ans;
	return 0;
}