Advertisement
heian

Untitled

Nov 7th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /**
  6. Algoritmul lui Euclid, cu care putem calcula
  7. CMMDC si CMMMC dintre doua numere
  8. */
  9.  
  10. /**
  11. CMMMDC(a,b) = CMMDC(a,a-b)
  12.  
  13. CMMMC(a,b) = a*b/CMMDC(a,b)
  14.  
  15. */
  16.  
  17. int main()
  18. {
  19. int a,b,r,A,B;
  20. cin>>a>>b;
  21. A = a;
  22. B = b;
  23. r = a%b;
  24. while(r>0)
  25. {
  26. a = b;
  27. b = r;
  28. r = a%b;
  29. }
  30.  
  31. cout<<"CMMDC="<<b<<"\n";
  32. cout<<"CMMMC="<<A*B/b<<"\n";
  33. return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement