Advertisement
monyca98

cel mai mare divizor comun impar

May 3rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int cmmdc(int a, int b)
  4. {
  5. while (b)
  6. {
  7. int r = a%b;
  8. a = b;
  9. b = r;
  10. }
  11. return a;
  12. }
  13.  
  14. int main()
  15. {
  16. int n, m;
  17. cin >> n >> m;
  18. int div = cmmdc(n, m);
  19. if (div % 2 == 0)
  20. div /= 2;
  21. while (div % 2 == 0)
  22. {
  23. div--;
  24. while (n%div != 0 && m%div!=0)
  25. div -= 2;
  26. }
  27. cout << div;
  28. cout << endl << endl;
  29. system("pause");
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement