結果

問題 No.1200 お菓子配り-3
ユーザー finefine
提出日時 2020-08-28 21:54:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,264 bytes
コンパイル時間 1,698 ms
コンパイル使用メモリ 162,308 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 22:47:54
合計ジャッジ時間 26,907 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,376 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 4 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 4 ms
5,376 KB
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 WA -
testcase_28 AC 3,141 ms
5,376 KB
testcase_29 AC 2,301 ms
5,376 KB
testcase_30 AC 2,299 ms
5,376 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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;

        // 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) {
            ++res;
            /*
            ll a = i - 1;
            ll c = (y - j) / (i - 2);
            ll b = j - c;
            res += (a > 0 && b > 0 && c > 0);*/
        }

        // b + c == i, a + 1 == j
        // c == (y - i) / (j - 2)
        if (j > 2 && y > i && (y - i) % (j - 2) == 0) {
            ++res;
            /*
            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