solution.cpp 620 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
#include <algorithm>
using namespace std;

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

    if ((y < x) && (-y <= x))
    {
        sum += x > 1 ? (long long)(4 * (2 + (abs(x) - 1) * (abs(x) - 2))) : 0; //求前n个正方形周长的等差数列和
        sum += (long long)x > 0 ? (4 * x + (x - y)) : (y - x);
    }
    else
    {
        sum += y > 1 ? (long long)(4 * (2 + (abs(y) - 1) * (abs(y) - 2))) : 0; //求前n个正方形周长的等差数列和
        sum += (long long)y > 0 ? (2 * y + y + x) : (6 * y - y - x);
    }

    cout << sum << endl;
    return 0;
}