Pagini recente » Cod sursa (job #3290213) | Cod sursa (job #3293161) | Cod sursa (job #3293281) | Cod sursa (job #3293809) | Cod sursa (job #3290657)
#include<bits/stdc++.h>
#define int long long
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;
}
}
int32_t 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;
}
}