Cod sursa(job #721956)

Utilizator robertpoeRobert Poenaru robertpoe Data 24 martie 2012 14:27:25
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#include <stdio.h>
#include <string.h>
#include<fstream>
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
const int n_max = 10001;
const int m = 1999999973;
unsigned int i, n, p,k,q;
long long a, sol = 1;
long long sum=0;
inline void maxpower(int x,int y)
{
	int a=x;
	for (int i = 0; (1<<i) <= y; ++ i)
	{
		if ( ((1<<i) & y) > 0)
			sol= (sol * a) % m;
			a=(a * a) % m;
	}
}
int main()
{
	f>>n>>k;
	maxpower(n,k);
	g<<sol;
}