Cod sursa(job #534846)
| Utilizator | Data | 16 februarie 2011 12:29:13 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include<stdio.h>
#define nrmax 1999999973
FILE *in,*out;
int i,baza,exponent;
long long puterea=1,baza_lucru;
int main()
{
in=fopen("lgput.in","rt");
out=fopen("lgput.out","wt");
fscanf(in,"%d%d",&baza,&exponent);
baza_lucru=baza;
for(i=0;(1<<i)<=exponent;i++)
{
if((1<<i)&exponent)
puterea=(puterea*baza_lucru)%nrmax;
baza_lucru=(baza_lucru*baza_lucru)%nrmax;
}
fprintf(out,"%lld",puterea);
return 0;
}
