Mai intai trebuie sa te autentifici.
Cod sursa(job #1296123)
Utilizator | Data | 20 decembrie 2014 16:20:46 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.69 kb |
#include <stdio.h>
#include <stdlib.h>
#define MODULO 1999999973
long long putere(long long baza, long long exponent) {
if ( exponent == 0 )
return 1;
else if ( exponent % 2 == 0) {
long long rez = putere(baza,exponent/2);
return ( rez % MODULO ) * ( rez % MODULO);
}
else {
long long rez = putere(baza,(exponent-1)/2);
return ( rez % MODULO ) * ( rez % MODULO ) * ( baza % MODULO);
}
}
int main()
{
FILE *in = fopen("lgput.in","r");
FILE *out = fopen("lgput.out","w");
long long baza, exponent;
fscanf(in,"%lld %lld", &baza, &exponent);
fprintf(out,"%lld",putere(baza,exponent));
fclose(in);
fclose(out);
return 0;
}