Cod sursa(job #1125547)

Utilizator h2g2Ford Prefect h2g2 Data 26 februarie 2014 18:19:15
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>
#define mod 1999999973LL
#define ll long long
using namespace std;

ll n, p;

ll raise(ll n, ll p) {
	if(p==1LL) return (n%mod);

	ll half = raise(n, p/2);
	if(p % 2 == 0) return ((half * half) % mod);
	return (((half * half * n) % mod;
}

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

	f>>n>>p;
	g<<raise(n, p)<<"\n";

	return 0;
}