Pagini recente » Cod sursa (job #3217503) | Cod sursa (job #2803009) | Cod sursa (job #2273449) | Cod sursa (job #1856913) | Cod sursa (job #933360)
Cod sursa(job #933360)
#include <stdio.h>
#include <iostream>
#include <utility>
#include <fstream>
using namespace std;
void gcd_ext(int a, int b, int &d, long long &x, long long &y)
{
if (b == 0)
{
d = a;
x = 1;
y = 0;
} else {
long long x0, y0;
gcd_ext(b, a%b, d, x0, y0);
x = y0;
y = x0 - (a / b)* y0;
}
}
/*
int prod_mod(int a, int b, int c)
{
a % c, b % c.
//need to return a*b mod c, but a*b might overflow
}
*/
int main()
{
freopen("euclid3.in", "r", stdin);
//freopen("euclid3.out", "w", stdout);
ofstream fout("euclid3.out");
int T;
scanf("%d", &T);
printf("%d\n", T);
int a,b,c;
int d;
long long x,y;
for(int i = 0; i < T; ++i)
{
scanf("%d %d %d", &a, &b, &c);
gcd_ext(a, b, d, x, y);
if (c % d) {printf("%d %d\n", 0, 0);}
else{
x = x * (c / d);
y = y * (c / d);
int tmp = b / d;
long long r = x % tmp;
long long q = x / tmp;
x = r;
y = y + (a / d)*q;
//printf("%I64d %I64d\n", x, y);
fout << x << " " << y << "\n";
}
}
return 0;
}