Cod sursa(job #3290656)
| Utilizator | Data | 31 martie 2025 15:08:04 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.57 kb |
#include<bits/stdc++.h>
using namespace std;
int euclid(int a, int b, int & x, int & y)
{
if(b == 0)
{
x = 1, y = 0;
return a;
}
else
{
int ans = euclid(b, a % b , x, y);
int aux = x;
x = y;
y = aux - (a / b) * y;
return ans;
}
}
int main()
{
freopen("inversmodular.in", "r", stdin);
freopen("inversmodular.out", "w", stdout);
int t;
cin >> t;
while(t--)
{
int a, b, c, x, y, ans;
cin >> a >> b;
euclid(a, b, x, y);
cout << (x + b) % b;
}
}