Cod sursa(job #1941976)

Utilizator SlenderSnaxOrban Abel SlenderSnax Data 27 martie 2017 18:39:27
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.48 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
int main()
{
	long long int num = 1999999973;
	int n, p, y = 1;
	in >> n;
	in >> p;
	int x = n;
	if (p <= 0) {
		if (p < 0) {
			n = 1 / n;
			p = -p;
		}
		if (p == 0)
			out << 1;
	}
	else {
		while (p > 1) {
			if (p % 2 == 0) {
				n*= n;
				p/= 2;
			}
			else {
				y*= n;
				n*= n;
				p = (p - 1) / 2;
			}
		}
	}
	n *= y;
	out << (n%num);
}