結果

問題 No.1200 お菓子配り-3
ユーザー hedwig100hedwig100
提出日時 2020-08-29 14:51:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 681 ms / 4,000 ms
コード長 1,370 bytes
コンパイル時間 1,819 ms
コンパイル使用メモリ 167,040 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 00:04:52
合計ジャッジ時間 6,966 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 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,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 6 ms
6,944 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 5 ms
6,940 KB
testcase_12 AC 32 ms
6,940 KB
testcase_13 AC 33 ms
6,944 KB
testcase_14 AC 32 ms
6,940 KB
testcase_15 AC 34 ms
6,940 KB
testcase_16 AC 33 ms
6,944 KB
testcase_17 AC 113 ms
6,944 KB
testcase_18 AC 162 ms
6,940 KB
testcase_19 AC 39 ms
6,940 KB
testcase_20 AC 310 ms
6,940 KB
testcase_21 AC 310 ms
6,944 KB
testcase_22 AC 364 ms
6,944 KB
testcase_23 AC 311 ms
6,940 KB
testcase_24 AC 305 ms
6,944 KB
testcase_25 AC 308 ms
6,944 KB
testcase_26 AC 308 ms
6,940 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 245 ms
6,944 KB
testcase_29 AC 681 ms
6,944 KB
testcase_30 AC 677 ms
6,940 KB
testcase_31 AC 2 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

void solve() {
    int x,y; cin >> x >> y;
    int ans = 0;
    if (x == y) {
        // A = 1
        ans = x - 1;
        // B = C
        for (int i = 1;i*i <= x; ++i) {
            if (x%i == 0) {
                if (x/i > 1) ++ans;
                if (i > 1 && x != i*i) ++ans;
            }
        }
        // A = 1 and B = C
        if (x%2 == 0) {
            --ans;
        }
        cout << ans << '\n';
        return ;
    }
    if (x < y) swap(x,y);
    int a = x + y,b = x - y;
    for (int i = 1;i*i <= b; ++i) {
        if (b%i == 0) {
            if (a%(i + 2) == 0 && a/(i + 2) > b/i && a/(i + 2)%2 == b/i%2) ++ans;
            int c = b/i;
            if (c == i) continue;
            if (a%(c + 2) == 0 && a/(c + 2) > i && i%2 == a/(c + 2)%2) ++ans;
        }
    }
    cout << ans << '\n';
}

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

    int T; cin >> T;
    rep(i,T) solve();
    return 0;
}
0