結果

問題 No.1200 お菓子配り-3
ユーザー KudeKude
提出日時 2020-10-02 18:54:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 799 ms / 4,000 ms
コード長 1,257 bytes
コンパイル時間 1,893 ms
コンパイル使用メモリ 205,100 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 00:25:57
合計ジャッジ時間 7,764 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 6 ms
6,944 KB
testcase_08 AC 5 ms
6,944 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 36 ms
6,944 KB
testcase_13 AC 37 ms
6,940 KB
testcase_14 AC 39 ms
6,940 KB
testcase_15 AC 41 ms
6,940 KB
testcase_16 AC 40 ms
6,940 KB
testcase_17 AC 136 ms
6,944 KB
testcase_18 AC 186 ms
6,940 KB
testcase_19 AC 44 ms
6,940 KB
testcase_20 AC 371 ms
6,940 KB
testcase_21 AC 359 ms
6,944 KB
testcase_22 AC 422 ms
6,940 KB
testcase_23 AC 369 ms
6,940 KB
testcase_24 AC 355 ms
6,940 KB
testcase_25 AC 361 ms
6,944 KB
testcase_26 AC 362 ms
6,940 KB
testcase_27 AC 1 ms
6,940 KB
testcase_28 AC 296 ms
6,944 KB
testcase_29 AC 790 ms
6,944 KB
testcase_30 AC 799 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>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

vector<int> divs(int x) {
    vector<int> res;
    for(int i = 1; i * i <= x; ++i) {
        if (x % i == 0) {
            res.push_back(i);
            if (i * i < x) {
                res.push_back(x / i);
            }
        }
    }
    return res;
}

int main() {
    int tt;
    cin >> tt;
    while(tt--) {
        int x, y;
        cin >> x >> y;
        if (x == y) {
            int ans = x - 1;
            for(int d: divs(x)) {
                if (d <= 2) continue;
                ++ans;
            }
            cout << ans << endl;
        } else {
            if (x < y) swap(x, y);
            int p = x + y, q = x - y;
            int ans = 0;
            for(int d: divs(q)) {
                int a = d + 1;
                if (p % (a + 1) == 0) {
                    int s = p / (a + 1), t = q / (a - 1);
                    ans += s > t && s % 2 == t % 2;
                }
            }
            cout << ans << endl;
        }
    }
}
0