a53

Fractzii_ANDRU

a53
Dec 12th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. ifstream fin("fractzii.in");
  5. ofstream fout("fractzii.out");
  6. ll n, m, c, k;
  7. ll cmmdc(ll a, ll b)
  8. {
  9. if (a == 0)
  10. return b;
  11. return cmmdc(b%a, a);
  12. }
  13. int main()
  14. {
  15. fin>>n>>m;
  16. c=cmmdc(n,m);
  17. n=n/c;
  18. m=m/c;
  19.  
  20. while(n!=1 && m!=1)
  21. {
  22. if(n>m)
  23. {
  24. k=k+n/m;
  25. n=n%m;
  26. }
  27. else
  28. {
  29. k=k+m/n;
  30. m=m%n;
  31. }
  32. }
  33. k=k+m+n-1;
  34. fout<<k;
  35. }
Add Comment
Please, Sign In to add comment