Cod sursa(job #2523279)
Utilizator | Data | 13 ianuarie 2020 21:35:56 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | c-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <stdio.h>
int main() {
FILE *fin = fopen( "inversmodular.in", "r" );
FILE *fout = fopen( "inversmodular.out", "w" );
int a, n, p = 1, mod;
fscanf( fin, "%d%d", &a, &n );
mod = n;
n -= 2;
while ( n > 0 ) {
if ( n % 2 == 1 ) {
p = (p * a) % mod;
}
a = (a * a) % mod;
n /= 2;
}
fprintf( fout, "%d", p );
fclose( fin );
fclose( fout );
return 0;
}