Cod sursa(job #1116765)
Utilizator | Data | 22 februarie 2014 19:58:08 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.3 kb |
#include<fstream>
#define nx 1999999973
using namespace std;
long long s,n,x;
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;
}