Pagini recente » Cod sursa (job #1438324) | Cod sursa (job #1756077) | Cod sursa (job #1213581) | Cod sursa (job #2422391) | Cod sursa (job #936639)
Cod sursa(job #936639)
#include<stdlib.h>
#include<stdio.h>
using namespace std;
long cmmdc(long a,long b, long & x, long & y) {
if(b == 0) {
x = 1;
y = 0;
return a;
}
else {
long xx, yy, d;
d = cmmdc(b,a%b,xx,yy);
x = yy;
y = xx-(a/b)*yy;
return d;
}
}
int main()
{
long a,b,c,d,x,y;
int t;
FILE *in,*out;
in = fopen("euclid3.in","r");
out = fopen("euclid3.out","w");
fscanf(in,"%d",&t);
for(int i = 0; i < t; i++) {
fscanf(in,"%ld%ld%ld",&a,&b,&c);
d = cmmdc(a,b,x,y);
if(c%d != 0)
fprintf(out,"0 0 \n");
else
fprintf(out,"%d %d \n",(c/d)*x,(c/d)*y);
}
return 0;
}