Cod sursa(job #966720)

Utilizator BlackElfSpulber Iosif BlackElf Data 26 iunie 2013 15:17:48
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.43 kb
#include <iostream>
#include <fstream>
#include <vector>

using namespace std;

int MOD = 1999999973;

int powMod (int n, int p)
{
	if (p % 2 == 0)
	{
		int aux = powMod (n, p/2) % MOD;
		return aux * aux;
	}
	else
	{
		return (n * powMod (n, p-1)) % MOD;
	}	
}

int main ()
{
	int n, p;
	ifstream in ("lgput.in");
	in >> n >> p;
	
	ofstream out ("lgput.out");
	out << powMod (n, p) << endl;

	return 0;
}