Pagini recente » Profil AlinLazar | Profil mad200647 | Rating Chira Codrin-Mihai (CCodrin) | Rating Epure-Tofanel Carlo (carloepure) | Cod sursa (job #2023472)
/*#include <bits/stdc++.h>
#define LUNGIME_MAX 1030
using namespace std;
ifstream fin("cmlsc.in");
ofstream fout("cmlsc.out");
int n,m;
int a[LUNGIME_MAX],b[LUNGIME_MAX];
int dp[LUNGIME_MAX][LUNGIME_MAX];
void solve(int x, int y) {
if(x==0||y==0) return;
if(a[x]==b[y]) {
solve(x-1,y-1);
} else {
if(dp[x-1][y]>dp[x][y-1])
solve(x-1, y);
else solve(x, y-1);
}
if(a[x]==b[y]) fout<<a[x]<<' ';
}
int main()
{
fin>>n>>m;
for(int i=1;i<=n;i++) fin>>a[i];
for(int j=1;j<=m;j++) fin>>b[j];
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
if(a[i] == b[j]) {
dp[i][j] = max(dp[i-1][j-1]+1, max(dp[i-1][j],dp[i][j-1]));
} else {
dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
}
}
fout<<dp[n][m]<<'\n';
solve(n, m);
return 0;
}
*/
/// Algoritmul lui Euclid extins
#include <fstream>
using namespace std;
ifstream f ("euclid3.in");
ofstream g ("euclid3.out");
long a,b,c,d,x,y,x0,y0,i,n;
long euclid(long a,long b,long &x,long &y)
{
if(b==0) {
x=1;
y=0;
return a;
}
else {long x0,y0;
d=euclid(b,a%b,x0,y0);
x=y0;
y=x0-(a/b)*y0;
return d;
}
}
int main()
{
f>>n;
for(i=1;i<=n;i++)
{
f>>a>>b>>c;
x=0;y=0;
d=euclid(a,b,x,y);
//cout<<x<<" " <<y<<" "<<d<<endl;;
if(c%d!=0) g<<0<<' '<<0<<'\n';
else g<<x*(c/d)<<' '<<y*(c/d)<<'\n';
}
g.close();
return 0;
}