Cod sursa(job #819602)
Utilizator | Data | 19 noiembrie 2012 13:41:26 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.57 kb |
#include<cstdlib>
#include<cstdio>
int putere(int &x,int &p)
{
int n=1;
while(p>0)
{
if(p%2==1)
{
n*=x;
p--;
}
x= x*x;
p/=2;
}
return n;
}
int main()
{
FILE *f,*g;
f=fopen("lgput.in","r");
g=fopen("lgput.out","w");
int x,p;
fscanf(f,"%d ",&x);
fscanf(f,"%d",&p);
fclose(f);
fprintf(g,"%d",putere(x,p)%1999999973);
fclose(g);
return 0;
}