Cod sursa(job #2557408)

Utilizator Chr1styDescultu Cristian Chr1sty Data 25 februarie 2020 19:36:42
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.5 kb
#include <iostream>
#include <fstream>
using namespace std;
const int m = 1999999973;
int main() {

 	ifstream myfile;
 	myfile.open("lgput.in");
 	ofstream outfile ("lgput.out");
 	int sol = 1;
 	int base, exponent;
 	myfile >> base >> exponent;
 	int basecpy = base;
 	for (unsigned int i = 0; (1 << i) <= exponent; ++i) {
 		if (((1 << i) & exponent) > 0) {
 			sol = (sol * basecpy) % m;
 		} 
 		basecpy = (basecpy * basecpy) % m;
 	}
 	outfile << sol;
 	myfile.close();
 	outfile.close();
	return 0;
}