Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- ifstream f("euclid3.in");
- ofstream g("euclid3.out");
- void cmmdcE(long long int a, long long int b, long long int &d, long long int &x, long long int &y)
- {
- int r,r0,r1,x0,x1,y0,y1,q;
- r0=a;
- r1=b;
- x0=1;
- y0=0;
- x1=0;
- y1=1;
- while (r1)
- {
- q=r0/r1;
- r=r0-r1*q;
- r0=r1;
- r1=r;
- x=x0-x1*q;
- x0=x1;
- x1=x;
- y=y0-y1*q;
- y0=y1;
- y1=y;
- }
- d=r0;
- x=x0;
- y=y0;
- }
- void Diofantic(long long int a, long long int b, long long int c)
- {
- long long int d,x0,y0;
- cmmdcE(a,b,d,x0,y0);
- if (c%d==0)
- g<<x0*c/d<<' '<<y0*c/d<<'\n';
- else
- g<<"0 0\n";
- }
- int main()
- {
- long long int n,a,b,c;
- f>>n;
- for (int i=0;i<n;i++)
- {
- f>>a>>b>>c;
- Diofantic(a,b,c);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement