fork download
  1. /* write your code below */
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. #define sti string
  6. #define vt vector
  7. #define pll pair<ll,ll>
  8. #define ld long double
  9. #define vll vector<ll>
  10. #define fi first
  11. #define se second
  12. #define be(x) x.begin(),x.end()
  13. #define pb push_back
  14. ll gcd(ll a, ll b) {return __gcd (a, b);}
  15. ll lcm(ll a, ll b) {return a / __gcd (a, b) * b;}
  16. //vnd
  17. const sti tenfile = "";
  18. const int MAXN = 3007;
  19. const int INF = 1000000005;
  20. const ll MOD = 1000000007;
  21. const ll INFLL = 3000000000000000000;
  22. const int LG = 60;
  23. const double eps = 1e-9;
  24.  
  25.  
  26.  
  27.  
  28. ll xa, ya, xb, yb, xc, yc;
  29.  
  30. vector<pair<ll, char>> get (ll x, ll y) {
  31. vector<pair<ll, char>> ans;
  32. while (x != y) {
  33. if (x > y) {
  34. ans.push_back({(x - 1) / y, 'R'});
  35. x -= (x - 1) / y * y;
  36. }
  37. else {
  38. ans.push_back({(y - 1) / x, 'L'});
  39. y -= (y - 1) / x * x;
  40. }
  41. }
  42.  
  43. return ans;
  44. }
  45.  
  46. ll dist (vector<pair<ll, char>> u, vector<pair<ll, char>> v) {
  47. ll su = 0, sv = 0, sl = 0;
  48. for (ll i = 0; i < min(u.size(), v.size()); i++) {
  49. if (u[i].se != v[i].se) break;
  50. if (u[i].fi != v[i].fi) {
  51. sl += min(u[i].fi, v[i].fi);
  52. break;
  53. }
  54. sl += u[i].fi;
  55. }
  56. for (ll i = 0; i < u.size(); i++) su += u[i].fi;
  57. for (ll i = 0; i < v.size(); i++) sv += v[i].fi;
  58.  
  59. return su + sv - 2 * sl;
  60. }
  61. int main() {
  62. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  63. // if (fopen((tenfile+".inp").c_str(),"r")) {
  64. // freopen((tenfile+".inp").c_str(),"r",stdin);
  65. // freopen((tenfile+".out").c_str(),"w",stdout);
  66. // }
  67. cin >> xa >> ya >> xb >> yb >> xc >> yc;
  68. vector<pair<ll, char>> a = get(xa, ya), b = get(xb, yb), c = get(xc, yc);
  69. cout << (dist(a, b) + dist(b, c) + dist(a, c)) / 2;
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0s 548KB
stdin
Standard input is empty
stdout
Standard output is empty