Cod sursa(job #1391284)
Utilizator | Data | 17 martie 2015 19:35:26 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <cstdio>
#define ll long long
#define MOD 1999999973
using namespace std;
FILE*f=fopen("lgput.in","r");
FILE*g=fopen("lgput.out","w");
ll x,n,p;
int main()
{
fscanf(f,"%d%d",&x,&n);
p=1;
while(n)
{
if((( x >> 1) << 1 ) == 1)
{
x=x*x;
if(x>MOD) x%=MOD;
n/=2;
}
else
{
p*=x;
if(p>MOD) p%=MOD;
n--;
}
}
fprintf(g,"%d\n",p);
return 0;
}