Advertisement
allia

рекурсивный быстрый евклид

Dec 5th, 2020
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. void fast_evklid (int a, int b)
  7. {
  8.   int nod;
  9.  
  10. if ( a != 0 && b != 0)
  11.  {
  12.    if (a > b)
  13.      {
  14.        a %= b;
  15.        return fast_evklid( a, b);
  16.      }
  17.   else
  18.      {
  19.        b%=a;
  20.        return fast_evklid( a, b);
  21.      }
  22.   }
  23.  else nod = a+b;
  24.  cout << nod;
  25. }
  26.  
  27. int main()
  28. {
  29.   int a, b;
  30.   cin >> a >> b;
  31.  fast_evklid (a, b);
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement