結果

問題 No.1200 お菓子配り-3
ユーザー nawawannawawan
提出日時 2020-08-28 22:50:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,582 bytes
コンパイル時間 1,075 ms
コンパイル使用メモリ 80,384 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 00:13:02
合計ジャッジ時間 41,014 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 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 6 ms
5,376 KB
testcase_06 AC 5 ms
5,376 KB
testcase_07 AC 31 ms
5,376 KB
testcase_08 AC 33 ms
5,376 KB
testcase_09 AC 31 ms
5,376 KB
testcase_10 AC 31 ms
5,376 KB
testcase_11 AC 31 ms
5,376 KB
testcase_12 AC 288 ms
5,376 KB
testcase_13 AC 297 ms
5,376 KB
testcase_14 AC 295 ms
5,376 KB
testcase_15 AC 295 ms
5,376 KB
testcase_16 AC 293 ms
5,376 KB
testcase_17 AC 1,052 ms
5,376 KB
testcase_18 AC 1,534 ms
5,376 KB
testcase_19 AC 356 ms
5,376 KB
testcase_20 AC 2,959 ms
5,376 KB
testcase_21 AC 2,986 ms
5,376 KB
testcase_22 AC 3,448 ms
5,376 KB
testcase_23 AC 2,937 ms
5,376 KB
testcase_24 AC 2,910 ms
5,376 KB
testcase_25 AC 2,892 ms
5,376 KB
testcase_26 AC 2,925 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 3,928 ms
5,376 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
vector<long long> divisor(long long n){//nの約数列挙
    vector<long long> res;
    for(long long i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    int test;
    cin >> test;
    for(int counttest = 0; counttest < test; counttest++){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        long long X, Y;
        cin >> X >> Y;
        long long ans = 0;
        if(X < Y) swap(X, Y);
        if(X == Y){
            long long t = X + Y;
            ans += t / 2 - 1;
            vector<long long> d = divisor(t);
            for(int i = 0; i < (int)d.size(); i++){
                if(d[i] > 1 && t / d[i] > 2) ans++;
            }
            cout << ans << endl;
        }
        else{
            long long t1 = X + Y, t2 = X - Y;
            vector<long long> d1 = divisor(t1), d2 = divisor(t2);
            sort(d1.begin(), d1.end());
            sort(d2.begin(), d2.end());
            for(int i = 0; i < (int)d1.size(); i++){
                if(d1[i] > 1){
                    long long temp = *lower_bound(d2.begin(), d2.end(), d1[i] - 2);
                    if(temp == d1[i] - 2 && (t1 / d1[i] + t2 / temp) % 2 == 0 && t1 / d1[i] > t2 / temp) ans++;
                }
            }
            cout << ans << endl;
        }
    }
}
0