Cod sursa(job #1701081)
Utilizator | Data | 12 mai 2016 09:03:30 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.4 kb |
#include <stdio.h>
int main () {
FILE *fin, *fout ;
fin = fopen ("lgput.in", "r" ) ;
fout = fopen ("lgput.out", "w" ) ;
long long a, p, n ;
fscanf(fin, "%lld%lld", &a, &n ) ;
p = 1 ;
while ( n > 0 ) {
if ( n % 2 == 1)
p = (p * a) % 1999999973 ;
a = (a * a) % 1999999973 ;
n = ( n / 2 ) % 1999999973 ;
}
fprintf(fout, "%lld", p );
return 0 ;
}