Cod sursa(job #2830952)
Utilizator | Data | 10 ianuarie 2022 15:59:31 | |
---|---|---|---|
Problema | Invers modular | Scor | 100 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.48 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
void euclid(int a, int b, int &x, int &y)
{
if(!b)
{
x = 1;
y = 0;
}
else
{
int x1,y1;
euclid(b, a%b, x1,y1);
x = y1;
y = x1 - (a/b)*y1;
}
}
int main()
{
int a, n,d,x,y;
f>>a>>n;
euclid(a,n,x,y);
while(x < 0)
x = x+n;
g<<x;
return 0;
}