Cod sursa(job #3257927)
| Utilizator | Data | 19 noiembrie 2024 22:48:27 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.46 kb |
#include <stdio.h>
#define p 1999999973
int main(){
unsigned int b, ans, pow;
FILE *fin, *fout;
fin = fopen( "lgput.in", "r" );
fscanf( fin, "%u%u", &b, &pow );
fclose( fin );
ans = 1;
while ( pow > 0 ) {
if ( pow % 2 == 1 )
ans = (ans * b) % p;
pow = pow / 2;
b = (b * b) % p;
}
fout = fopen( "lgput.out", "w" );
fprintf( fout, "%u\n", ans );
fclose( fout );
return 0;
}
