Cod sursa(job #1116762)
Utilizator | Data | 22 februarie 2014 19:55:34 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.31 kb |
#include<fstream>
#define nx 1999999973
using namespace std;
int n,x;
long long s;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int main()
{
fin>>x>>n;
s=1;
while(n)
{
if(n%2)s=(s*x)%nx,n--;
else x=(x*x)%nx,n/=2;
}
fout<<s;
return 0;
}