Vasya and Triangle - codeforce

ps:假设三角形的两条直角边为a,b,则 n * m / k = a * b / 2,如果等式成立,就 (2 * n * m)% k == 0,怎么构造a,b?暴力貌似不行,考虑一下gcd。注意一点:2应该乘在哪个数身上!

P p[3];
LL n, m, k;

LL gcd(LL a, LL b) {
    return (!b ? a : gcd(b, a % b));
}

int main()
{
    cin >> n >> m >> k;

    if (2 * n * m % k != 0) {
        puts("NO");
        return 0;
    }

    puts("YES");
    bool flag = (n > m);

    int g = gcd(n, k);
    n /= g, k /= g;

    int t = gcd(m, k);
    m /= t, k /= t;

    if (g != 1 && k == 1) n = 2 * n;
    else if (t != 1 && k == 1) m = 2 * m;

    p[0].first = p[0].second = 0;
    if (flag) {
        p[1].first = max(n, m), p[1].second = 0;
        p[2].first = 0, p[2].second = min(n, m);

    }
    else {
        p[1].first = min(n, m), p[1].second = 0;
        p[2].first = 0, p[2].second = max(n, m);
    }

    rep(i, 0, 3) cout << p[i].first << " " << p[i].second << endl;
    return 0;
}

 

posted @ 2018-09-24 10:30  天之道,利而不害  阅读(467)  评论(0编辑  收藏  举报