Cod sursa(job #1691210)

Utilizator vasica38Vasile Catana vasica38 Data 17 aprilie 2016 13:36:35
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include<fstream>
#define mod 1999999973
using namespace std;
long long  x, p, n, y;
int main()
{
	ifstream cin("lgput.in");
	ofstream cout("lgput.out");
	cin >> x >> n;
	 p = 1;
	 y = 1;
	 while (n > 1)
	 {
		 if (n & 1)
		 {
			 y = (y*x) % mod;
			 x = (x*x) % mod;
			 n = (n - 1) / 2;
		 }
		 else
		 {
			 x =( x*x)%mod;
			 n = n / 2;
		 }
	 }
	 cout <<( x*y)%mod;
	 return 0;
}