# 14062: 【原4062】日天圈地

### 题目描述

author: AimAlex 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/4062

## Sample Input

``````1 2
``````

## Sample Output

``````8
``````

## BugenZhao's solution

``````//
// Created by BugenZhao on 2019/3/17.
//
// 辗转相除

#include <iostream>
#include <algorithm>

using namespace std;

static const auto _____ = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
return nullptr;
}();

using ll=long long;

ll get(ll a, ll b) {
if (b == 0)
return 0;
ll adb = a / b;
}

int main() {
ll a, b;
cin >> a >> b;
if (a < b) swap(a, b);
cout << get(a, b);
return 0;
}
``````

## FineArtz's solution

``````/* 日天圈地 */
#include <iostream>
using namespace std;

long long f(long long x, long long y){
long long t, ret;
if (x > y){
t = x;
x = y;
y = t;
}
ret = 4 * x * (y / x);
y = y % x;
if (y == 0) return ret;
else return ret + f(y, x);
}

int main(){
long long x, y, ans;
cin >> x >> y;
ans = f(x, y);
cout << ans << endl;
return 0;
}
``````

## ligongzzz's solution

``````#include "iostream"
#include "cstdio"
using namespace std;

long long cal(long long x, long long y) {
if (y == 0 || x == 0)
return 0;
if (y >= x) {
return cal(x, y % x) + y / x * x * 4;
}
else {
return cal(x % y, y) + x / y * y * 4;
}
}

int main() {
long long x, y;
cin >> x >> y;

cout << cal(x, y);

return 0;
}
``````

## q4x3's solution

``````/**
* 模拟
* 将矩形较短的边作为正方形边长
* 注意long long
**/
#include <iostream>

using namespace std;

long long m, n, ans;
int main() {
cin >> m >> n;
while(m != 0 || n != 0) {
if(m == n) {
ans += 4 * m;
break;
}
if(m > n) {
ans += 4 * n;
m = m - n;
}
if(m < n) {
ans += 4 * m;
n = n - m;
}
}
cout << ans << endl;
}
``````

## skyzh's solution

``````#include <iostream>
using namespace std;

int main() {
long long x, y, res = 0;
cin >> x >> y;
while (x > 0) {
if (x < y) swap(x, y);
res += y * 4;
long long c = x - y;
x = y; y = c;
}
cout << res << endl;
return 0;
}
``````

## victrid's solution

``````#include <iostream>
using namespace std;
long long seq(long long x, long long y) {
if (x < y)
return seq(y, x);
if (y == 0)
return 0;
return x / y * 4 * y + seq(y, x % y);
}
int main() {
long long x, y;
cin >> x >> y;
cout << seq(x, y);
return 0;
}
``````

## WashSwang's solution

``````#include <iostream>
using namespace std;
long long a,b;
long long x(long long a,long long b)
{
if (b!=0)
return a/b*4*b+x(b,a%b);
else return 0;
}
int main() {
cin>>a>>b;
cout<<x(a,b);
return 0;
}
``````