結果

問題 No.1200 お菓子配り-3
ユーザー daikisuyamadaikisuyama
提出日時 2020-08-29 09:16:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,904 bytes
コンパイル時間 2,023 ms
コンパイル使用メモリ 176,856 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-27 00:59:02
合計ジャッジ時間 18,389 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 13 ms
6,944 KB
testcase_08 AC 14 ms
6,944 KB
testcase_09 AC 13 ms
6,940 KB
testcase_10 AC 12 ms
6,940 KB
testcase_11 AC 11 ms
6,940 KB
testcase_12 AC 108 ms
6,940 KB
testcase_13 AC 112 ms
6,940 KB
testcase_14 AC 111 ms
6,940 KB
testcase_15 AC 114 ms
6,944 KB
testcase_16 AC 110 ms
6,944 KB
testcase_17 AC 397 ms
6,940 KB
testcase_18 AC 574 ms
6,940 KB
testcase_19 AC 132 ms
6,940 KB
testcase_20 AC 1,110 ms
6,940 KB
testcase_21 AC 1,104 ms
6,944 KB
testcase_22 AC 1,299 ms
6,940 KB
testcase_23 AC 1,105 ms
6,940 KB
testcase_24 AC 1,084 ms
6,940 KB
testcase_25 AC 1,091 ms
6,940 KB
testcase_26 WA -
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 869 ms
6,940 KB
testcase_29 AC 2,420 ms
6,940 KB
testcase_30 AC 2,420 ms
6,940 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//デバッグ用オプション:-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
//FORAは範囲for文(使いにくかったら消す)
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

ll check_divisors(ll x,ll y){
    ll n=abs(x-y);
    ll ret=0;
    FOR(i,1,sqrt(n)){
        if(n%i==0){
            ll a,b;
            if(i!=ll(n/i)){
                a=i;b=ll(n/i);
                if((x+y)%(a+2)==0){
                    if(ll((x+y)/(a+2))%2==b%2){
                        if(b<ll((x+y)/(a+2)))ret++;
                        //cout<<a<<" "<<b<<" "<<a+2<<" "<<ll((x+y)/(a+2))<<endl;
                    }
                }
                a=ll(n/i);b=i;
                if((x+y)%(a+2)==0){
                    if(ll((x+y)/(a+2))%2==b%2){
                        if(b<ll((x+y)/(a+2)))ret++;
                        //cout<<a<<" "<<b<<" "<<a+2<<" "<<ll((x+y)/(a+2))<<endl;
                    }
                }
            }else{
                a=i;b=i;
                if(ll((x+y)/(a+2))%2==b%2){
                    if(b<ll((x+y)/(a+2)))ret++;
                    //cout<<a<<" "<<b<<" "<<a+2<<" "<<ll((x+y)/(a+2))<<endl;
                }
            }
        }
    }
    return ret;
}

ll check_divisors2(ll x,ll y){
    ll ret=x-1;
    FOR(i,2,sqrt(x)){
        if(x%i==0){
            if(i!=ll(x/i)){
                if(i!=2)ret+=2;
                else if(i==2 and x%2==0) ret++;
                else ret+=2;
            }else{
                if(i!=2)ret++;
            }
        }
    }
    //b=1の時
    if(x!=2 and x!=1)ret++;
    return ret;
}

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll s;cin>>s;
    REP(i,s){
        ll x,y;cin>>x>>y;
        if(x==y){
            cout<<check_divisors2(x,y)<<endl;
        }else{
            cout<<check_divisors(x,y)<<endl;
        }
    }
}
0