Advertisement
andreisophie

Euclid3

Sep 10th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <fstream>
  2.  
  3. using namespace std;
  4.  
  5. ifstream f("euclid3.in");
  6. ofstream g("euclid3.out");
  7.  
  8. void cmmdcE(long long int a, long long int b, long long int &d, long long int &x, long long int &y)
  9. {
  10.     long long int x0, y0;
  11.     if (b==0)
  12.     {
  13.         d=a;
  14.         x=1;
  15.         y=0;
  16.     }
  17.     else
  18.     {
  19.         cmmdcE(b,a%b,d,x0,y0);
  20.         x=y0;
  21.         y=x0-(a/b)*y0;
  22.     }
  23. }
  24.  
  25. void Diofantic(long long int a, long long int b, long long int c)
  26. {
  27.     long long int d,x0,y0;
  28.     cmmdcE(a,b,d,x0,y0);
  29.     if (c%d==0)
  30.         g<<x0*c/d<<' '<<y0*c/d<<'\n';
  31.     else
  32.         g<<"0 0\n";
  33. }
  34.  
  35. int main()
  36. {
  37.     long long int n,a,b,c;
  38.     f>>n;
  39.     for (int i=0;i<n;i++)
  40.     {
  41.         f>>a>>b>>c;
  42.         Diofantic(a,b,c);
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement