墙壁划线

https://www.nowcoder.com/discuss/774332771186565120?sourceSSR=search

重点:

求网格顶点,也就是又和竖线有交点又和横线有焦点

所以最重要的就是要确认x和y必须是整数,所以要求a和b的最大公约数

 

#include <iostream>
#include <numeric>

using namespace std;
using LL = long long;

int main() {
    LL a, b, x, y;
    cin >> a >> b >> x >> y;
    
    LL total_points = 2 * (a + b + 1 - gcd(a, b));
    if (a % 2 == 0 || b % 2 == 0) {
        total_points--;
    }
    
    cout << total_points << endl;
    
    return 0;
}

 

posted @ 2025-07-20 17:20  最近饭吃的很多  阅读(6)  评论(0)    收藏  举报