Cod sursa(job #1095770)

Utilizator andreifirstCioara Andrei Ioan andreifirst Data 31 ianuarie 2014 20:40:53
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <iomanip>
#include <cmath>

#define e '\n'

using namespace std;

#define FILE "lgput"

#define INF 1023456789

#ifdef FILE
	ifstream f(string (string(FILE) + ".in").c_str());
	ofstream g(string (string(FILE) + ".out").c_str());
#endif
#ifndef FILE
	#define f cin
	#define g cout
#endif

int i, j, n, m;

#define NMOD 1999999973

int pw(int x, int y) {
	if (y == 1) return x % NMOD;
	if (y == 0) return 1;
	int tmp = pw (x, y/2);
	if (y % 2 == 0) {
		return tmp * tmp % NMOD;
	}

	return tmp * tmp * x % NMOD;
}

int main() {

	f >> n >> m;

	g << pw(n, m) << e;

}