Advertisement
Gideer

Untitled

Dec 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include<cassert>
  3. using namespace std;
  4.  
  5. int gcd(int a, int b)
  6. {
  7. // Everything divides 0
  8. if (a == 0 || b == 0)
  9. return 0;
  10.  
  11. // Base case
  12. if (a == b)
  13. return a;
  14.  
  15. // a is greater
  16. if (a > b)
  17. return gcd(a-b, b);
  18. return gcd(a, b-a);
  19. }
  20.  
  21.  
  22. // Function to return LCM of two numbers
  23. int lcm(int a, int b)
  24. {
  25. return (a*b)/gcd(a, b);
  26. }
  27.  
  28. int main(){
  29. int x,y,wx,wy;
  30. cin >> x >> y;
  31. assert(x>0 && y>0);
  32. wx = x;
  33. assert(wx==x);
  34. wy = y;
  35. assert(wy==y);
  36. //NIEZMIENNIK
  37.  
  38.  
  39. while(wx!=wy){
  40. assert(wx!=wy);
  41. if (wx>wy){
  42. assert(wx!=wy && wx>wy);
  43. assert(wy!=wy+y);
  44. wy = wy + y;
  45. }
  46. else{
  47. assert(wx<wy && wx!=wx+x);
  48. wx = wx + x;
  49. }
  50. }
  51.  
  52.  
  53. // assert(wx==nww(x,y));
  54. cout << wx << endl;
  55. cout << lcm(2,3);
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement