Cod sursa(job #1691209)
Utilizator | Data | 17 aprilie 2016 13:35:35 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include<fstream>
#define mod 1999999973
using namespace std;
int 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;
}