Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int cmmdc(int a,int b)
  6. {
  7. int r=0;
  8. while(b)
  9. {
  10. r = a % b;
  11. a = b;
  12. b = r;
  13. }
  14. return a;
  15. }
  16.  
  17. int main()
  18. {
  19. int a, b, p = 2;
  20. cin >> a >> b;
  21. while(a)
  22. {
  23. while(1.0/p > 1.0*a/b)
  24. p++;
  25. cout << p << " ";
  26. a = a * p - b;
  27. if(a)
  28. {
  29. b = b * p;
  30. int d = cmmdc(a,b);
  31. a = a/d;
  32. b = b/d;
  33. }
  34. }
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement