Pagini recente » Cod sursa (job #224072) | Cod sursa (job #2738142) | Cod sursa (job #2806677) | Cod sursa (job #1239803) | Cod sursa (job #792525)
Cod sursa(job #792525)
#include<stdio.h>
void euclid (long long a, long long b, long long &x, long long &y)
{
if ( b == 0 )
{
x = 1;
y = 0;
}
else
{
long long x0, y0;
euclid (b, a%b, x0, y0);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main ()
{
long long x, y;
int a, n;
FILE *fis = fopen ("inversmodular.in", "r");
fscanf(fis, "%d %d", &a, &n);
fclose(fis);
euclid (a, n, x, y);
if ( x <= 0 )
x = n + x%n;
FILE *fis2 = fopen ("inversmodular.out", "w");
fprintf(fis2, "%lld\n", x);
fclose(fis2);
return 0;
}