結果

問題 No.1200 お菓子配り-3
ユーザー w2w2w2w2
提出日時 2020-08-29 00:08:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,395 ms / 4,000 ms
コード長 2,076 bytes
コンパイル時間 1,737 ms
コンパイル使用メモリ 172,648 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 00:02:30
合計ジャッジ時間 18,107 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 13 ms
6,940 KB
testcase_08 AC 13 ms
6,940 KB
testcase_09 AC 13 ms
6,940 KB
testcase_10 AC 13 ms
6,944 KB
testcase_11 AC 12 ms
6,940 KB
testcase_12 AC 107 ms
6,944 KB
testcase_13 AC 109 ms
6,940 KB
testcase_14 AC 108 ms
6,944 KB
testcase_15 AC 111 ms
6,944 KB
testcase_16 AC 110 ms
6,944 KB
testcase_17 AC 391 ms
6,940 KB
testcase_18 AC 562 ms
6,940 KB
testcase_19 AC 131 ms
6,940 KB
testcase_20 AC 1,084 ms
6,940 KB
testcase_21 AC 1,083 ms
6,940 KB
testcase_22 AC 1,286 ms
6,940 KB
testcase_23 AC 1,085 ms
6,940 KB
testcase_24 AC 1,068 ms
6,940 KB
testcase_25 AC 1,076 ms
6,940 KB
testcase_26 AC 1,083 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 853 ms
6,944 KB
testcase_29 AC 2,395 ms
6,940 KB
testcase_30 AC 2,381 ms
6,940 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
constexpr ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll S;
    cin >> S;
    REP(lsdgf,S){
        ll X,Y;
        cin >> X >> Y;
        ll sum = X+Y;
        ll dif = abs(X-Y);
        vector<ll> divisor(0);
        for(ll l = 1;l*l <= dif;l++){
            if(dif % l == 0){
                divisor.eb(l);
                if(l*l != dif)divisor.eb(dif / l);
            }
        }
        ll count = 0;
        REP(i,divisor.size()){
            if(sum % (divisor[i]+2) != 0)continue;
            ll B = sum/(divisor[i]+2) + dif/divisor[i];
            if(B % 2 != 0)continue;
            ll C = sum/(divisor[i]+2) - dif/divisor[i];
            if(C %  2 != 0)continue;
            if(B <= 0 || C <= 0)continue;
            count++;
        }
        if(X == Y){
            vector<ll> divisor(0);
            for(ll l = 1;l*l <= sum;l++){
                if(sum % l == 0){
                    divisor.eb(l);
                    if(l*l != sum)divisor.eb(sum / l);
                }
            }
            count = 0;
            REP(i,divisor.size()){
                if(divisor[i] == 1)continue;
                if(divisor[i] == 2){
                    count += X-1;
                    continue;
                }
                if(sum/divisor[i]%2 == 0)count++;
            }
        }
        cout << count << "\n";
    }
}
0