Cod sursa(job #558158)
Utilizator | Data | 17 martie 2011 09:33:14 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.36 kb |
#include <cstdio>
using namespace std;
int n,p,px,r,rez;
int main()
{
FILE* f=fopen("lgput.in","r");
FILE* g=fopen("lgput.out","w");
fscanf(f,"%d %d",&n,&p);
px=p;
rez=1;
while (n)
{
r=n%2;
if (r)
rez*=px;
rez=rez%1999999973;
px*=px;
px=px%1999999973;
n/=2;
}
fprintf(g,"%d\n",rez);
fclose(f);
fclose(g);
return 0;
}