Mai intai trebuie sa te autentifici.
Cod sursa(job #3358284)
| Utilizator | Data | 16 iunie 2026 01:58:12 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 100 |
| Compilator | c-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include <stdio.h>
#include <stdlib.h>
void inv_mod(long long a, long long b, long long *x, long long *y)
{
if (b == 0)
{
*x = 1;
*y = 0;
return;
}
long long x1, y1;
inv_mod(b, a % b, &x1, &y1);
*x = y1;
*y = x1 - (a / b) * y1;
}
int main(void)
{
long long a, n, x, y;
FILE *in = fopen("inversmodular.in", "r");
FILE *out = fopen("inversmodular.out", "w");
fscanf(in, "%lld %lld", &a, &n);
inv_mod(a, n, &x, &y);
x = (x % n + n) % n;
fprintf(out, "%lld", x);
return 0;
}