Cod sursa(job #1660480)
Utilizator | Data | 23 martie 2016 10:01:15 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
#define NR 1999999973
using namespace std;
int main()
{
ifstream cin ("lgput.in");
ofstream cout ("lgput.out");
long long int x,y=1,puterea,numarul;
cin >> x >> puterea;
while (puterea>1)
{
if (puterea%2==0)
{
x=(x*x)%NR;
puterea=puterea/2;
}
else
{
y=(x*y)%NR;
x=(x*x)%NR;
puterea=(puterea-1)/2;
}
}
numarul=(x*y)%NR;
cout << numarul;
return 0;
}