Cod sursa(job #1734262)
| Utilizator | Data | 26 iulie 2016 22:00:10 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.73 kb |
#include <iostream>
#include <fstream>
using namespace std;
const int m = 1999999973;
int expLogTime(int x, int n);
int main()
{
int x, y;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
fin >> x >> y;
fout << expLogTime(x,y) << '\n';
fin.close();
fout.close();
return 0;
}
int expLogTime(int x, int n)
{
int aux = 1;
if (n==0)
return 1;
if(n== 1)
return (x%m);
while(n > 1)
{
if(n%2)
{
aux = (aux*x) %m;
x = (x*x) %m;
n = (n-1)/2;
}
else
{
x =(x*x)%m;
n = n/2;
}
}
return (x *aux)%m;
}
