結果

問題 No.1200 お菓子配り-3
ユーザー yuuiyuui
提出日時 2020-08-28 22:48:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,489 bytes
コンパイル時間 2,937 ms
コンパイル使用メモリ 203,364 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 00:09:42
合計ジャッジ時間 42,692 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 5 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 33 ms
5,376 KB
testcase_08 AC 34 ms
5,376 KB
testcase_09 AC 32 ms
5,376 KB
testcase_10 AC 32 ms
5,376 KB
testcase_11 AC 31 ms
5,376 KB
testcase_12 AC 285 ms
5,376 KB
testcase_13 AC 294 ms
5,376 KB
testcase_14 AC 295 ms
5,376 KB
testcase_15 AC 296 ms
5,376 KB
testcase_16 AC 294 ms
5,376 KB
testcase_17 AC 1,063 ms
5,376 KB
testcase_18 AC 1,514 ms
5,376 KB
testcase_19 AC 354 ms
5,376 KB
testcase_20 AC 2,950 ms
5,376 KB
testcase_21 AC 2,922 ms
5,376 KB
testcase_22 AC 3,482 ms
5,376 KB
testcase_23 AC 2,923 ms
5,376 KB
testcase_24 AC 2,913 ms
5,376 KB
testcase_25 AC 2,908 ms
5,376 KB
testcase_26 AC 2,920 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 3,946 ms
5,376 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
    ll X, Y;
    cin >> X >> Y;
    if (X == Y) {
        ll ans = X - 1;
        ll t = 2;
        while (t * t <= X) {
            if (X % t == 0) {
                if (t * t == X) {
                    ans++;
                } else {
                    ans += 2;
                }
            }
            t++;
        }
        if (X > 1) {
            ans += 1;
        }
        cout << ans << "\n";
        return;
    }
    if (X < Y) {
        swap(X, Y);
    }

    ll PN = X + Y;
    unordered_map<ll, ll> plus;
    ll t = 1;
    while (t * t <= PN) {
        if (PN % t == 0) {
            plus[t] = PN / t;
            plus[PN / t] = t;
        }
        t++;
    }

    ll MN = X - Y;
    unordered_map<ll, ll> minus;
    t = 1;
    while (t * t <= MN) {
        if (MN % t == 0) {
            minus[t] = MN / t;
            minus[MN / t] = t;
        }
        t++;
    }

    ll ans = 0;
    for (auto itr = minus.begin(); itr != minus.end(); ++itr) {
        ll num = itr->first;
        ll target = itr->second;
        if (plus.find(num + 2) != plus.end()) {
            if ((plus[num + 2] + target) % 2 == 0 && plus[num + 2] > target) {
                ans++;
            }
        }
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll S;
    cin >> S;
    for (int i = 0; i < S; i++) {
        solve();
    }

    return 0;
}
0