結果

問題 No.1200 お菓子配り-3
ユーザー finefine
提出日時 2020-08-30 03:14:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,401 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 166,572 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 01:30:23
合計ジャッジ時間 11,672 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 1,106 ms
6,940 KB
testcase_29 AC 855 ms
6,944 KB
testcase_30 AC 849 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = int;

constexpr char newl = '\n';

ll solve(ll x, ll y) {    
    // x = ab+c, y = ac+b
    // x + y = (a + 1)(b + c)
    ll sum = x + y;
    ll res = 0;
    for (ll i = 2; i * i <= sum; i++) {
        if (sum % i != 0) continue;
        ll j = sum / i;

        if (i == 2) {
            res += j - 1 + (i != j);
            continue;
        }

        if (j == 2) {
            res += i - 1 + (i != j);
            continue;
        }

        // a + 1 == i, b + c == j
        // (i - 1) c + (j - c) == y
        // (i - 2) c + j == y
        // c == (y - j) / (i - 2)
        if (i > 2 && y > j && (y - j) % (i - 2) == 0) {
            ll a = i - 1;
            ll c = (y - j) / (i - 2);
            ll b = j - c;
            res += (a > 0 && b > 0 && c > 0);
        }

        if (i == j) continue;

        // b + c == i, a + 1 == j
        // c == (y - i) / (j - 2)
        if (j > 2 && y > i && (y - i) % (j - 2) == 0) {
            ll a = j - 1;
            ll c = (y - i) / (j - 2);
            ll b = i - c;
            res += (a > 0 && b > 0 && c > 0);            
        }
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        cout << solve(x, y) << newl;
    }

    return 0;
}
0