Cod sursa(job #1017080)

Utilizator jsteJames Sawyer jste Data 27 octombrie 2013 10:17:12
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <list>
#include <deque>
#include <vector>
#include <string>
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define NMOD 1999999973

using namespace std;

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

long int exp(int b, int e);

int main()
{
	int n,p;
	f>>n>>p;
	g<<exp(n,p)%NMOD;
	return 0;
}

long int exp(int b,int e)
{
	int h=0;
	if(e==1) return b%NMOD;
	if(e%2==0) 
	{
		h=exp(b,e/2)%NMOD;
		return h*h%NMOD;
	}
	else
	{
		h=exp(b,e/2)%NMOD;
		return (((h*h)%NMOD)*b)%NMOD;
	}
}