Cod sursa(job #932423)

Utilizator h2g2Ford Prefect h2g2 Data 28 martie 2013 21:41:45
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <iostream>
#include <fstream>
#define mod 1999999973
#define ll long long
using namespace std;

ll pow(ll n, ll exp) {
	if(exp == 0) return 1;
	
	ll jumatate = pow(n, exp/2) % mod;
	
	if(exp % 2 == 0) return ((jumatate * jumatate) % mod);
	return ((((jumatate * jumatate) % mod) * n) % mod);
}

int main() {
	ifstream f("lgput.in");
	ofstream g("lgput.out");

	ll n, exp;
	f>>n>>exp;

	g<<pow(n, exp)<<"\n";
	
	return 0;
}