結果

問題 No.1200 お菓子配り-3
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2020-08-29 16:06:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,626 ms / 4,000 ms
コード長 1,469 bytes
コンパイル時間 1,559 ms
コンパイル使用メモリ 173,888 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 00:08:06
合計ジャッジ時間 16,169 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 12 ms
6,944 KB
testcase_08 AC 13 ms
6,944 KB
testcase_09 AC 12 ms
6,944 KB
testcase_10 AC 13 ms
6,940 KB
testcase_11 AC 12 ms
6,940 KB
testcase_12 AC 100 ms
6,940 KB
testcase_13 AC 105 ms
6,944 KB
testcase_14 AC 106 ms
6,944 KB
testcase_15 AC 110 ms
6,940 KB
testcase_16 AC 104 ms
6,944 KB
testcase_17 AC 371 ms
6,940 KB
testcase_18 AC 538 ms
6,944 KB
testcase_19 AC 123 ms
6,944 KB
testcase_20 AC 1,026 ms
6,940 KB
testcase_21 AC 1,029 ms
6,940 KB
testcase_22 AC 1,219 ms
6,944 KB
testcase_23 AC 1,037 ms
6,940 KB
testcase_24 AC 1,022 ms
6,944 KB
testcase_25 AC 1,030 ms
6,944 KB
testcase_26 AC 1,044 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 1,395 ms
6,940 KB
testcase_29 AC 1,608 ms
6,944 KB
testcase_30 AC 1,626 ms
6,944 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.29 16:05:53
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;



template<typename T>
vector<T> enum_div(T n) {
    vector<T> ret;
    for (T i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}
int main() {
    int n;cin >> n;
    while(n--) {
        int x,y;scanf("%d %d",&x,&y);
        if (x == y) {
            ll ans = 0;
            ans += x - 1;
            ans += enum_div(x).size() - 1;
            if (x % 2 == 0) ans--;
            printf("%lld\n", ans);
        }
        else {
            if (x < y) swap(x,y);
            auto v1 = enum_div(x + y);
            sort(v1.begin(), v1.end());
            auto v2 = enum_div(x - y);
            sort(v2.begin(), v2.end());
            int t = 0;
            int ans = 0;
            for (int i = 0; i < v2.size(); i++) {
                while(t < v1.size() && v2[i] + 2 >= v1[t]) {
                    if (v2[i] + 2 == v1[t]) {
                        int a = v1[v1.size()-1] / v1[t];
                        int b = v2[v2.size()-1] / v2[i];
                        if (a > b && a % 2 == b % 2) ans++;
                    }
                    t++;
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}
0