結果

問題 No.1200 お菓子配り-3
ユーザー yuui
提出日時 2020-08-29 00:41:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,345 bytes
コンパイル時間 2,294 ms
コンパイル使用メモリ 191,648 KB
最終ジャッジ日時 2025-01-13 19:50:53
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void solve() {
    int 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);
    }

    int PN = X + Y;

    int ans = 0;

    int MN = X - Y;
    int t = 1;
    while (t * t <= MN) {
        if (MN % t == 0) {
            int n = MN / t;
            if (PN % (t + 2) == 0) {
                int target = PN / (t + 2);
                if ((target + n) % 2 == 0 && target > n) {
                    ans++;
                }
            }

            if (n != t && PN % (n + 2) == 0) {
                int target = PN / (n + 2);
                if ((target + t) % 2 == 0 && target > t) {
                    ans++;
                }
            }
        }
        t++;
    }

    cout << ans << "\n";
}

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

    return 0;
}
0