Pagini recente » Cod sursa (job #2906451) | Cod sursa (job #2768254) | Cod sursa (job #2260275) | Cod sursa (job #2931783) | Cod sursa (job #2900395)
#include <bits/stdc++.h>
using namespace std;
ifstream f("inversmodular.in");
ofstream g("inversmodular.out");
int euclid_extins(int &x, int &y, int a, int b){
if(b == 0){
x = 1;
y = 0;
return a;
}
else{
int x1 , y1;
int t = euclid_extins(x1, y1, b, a%b);
x = y1;
y = x1 - y1 * (a / b);
return t;
}
}
int main(){
int n;
f >> n;
for(int i = 0;i<n;++i){
int a, b, c;
f >> a >> b >> c;
int x, y;
euclid_extins(x,y,a,b);
if(x < 0)
x += b;
if(y < 0)
y += b;
int t = euclid_extins(x,y,a,b);
if(c%t == 0){
int aux = c/t;
g << x*aux << ' ' << y*aux << endl;
}
else g << 0 << ' ' << 0 << endl;
}
}