結果

問題 No.1200 お菓子配り-3
ユーザー DriceDrice
提出日時 2020-08-28 22:39:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 948 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 31,908 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-09 09:22:00
合計ジャッジ時間 16,558 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 3 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 13 ms
4,384 KB
testcase_08 AC 13 ms
4,384 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 12 ms
4,380 KB
testcase_11 AC 11 ms
4,384 KB
testcase_12 AC 104 ms
4,380 KB
testcase_13 AC 106 ms
4,380 KB
testcase_14 AC 106 ms
4,380 KB
testcase_15 AC 108 ms
4,384 KB
testcase_16 AC 105 ms
4,380 KB
testcase_17 AC 379 ms
4,384 KB
testcase_18 AC 547 ms
4,380 KB
testcase_19 AC 126 ms
4,380 KB
testcase_20 AC 1,051 ms
4,380 KB
testcase_21 AC 1,052 ms
4,380 KB
testcase_22 AC 1,242 ms
4,380 KB
testcase_23 AC 1,056 ms
4,384 KB
testcase_24 AC 1,036 ms
4,380 KB
testcase_25 AC 1,045 ms
4,380 KB
testcase_26 AC 1,045 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 826 ms
4,384 KB
testcase_29 AC 2,318 ms
4,384 KB
testcase_30 AC 2,318 ms
4,380 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>

long long getCnt(long long a,long long x,long long y){
    //printf("a = %lld\n",a);
    if(a==1){
        if(x!=y) return 0;
        else return x-1;
    }
    else{
        //b-c
        long long k = (x-y)/(a-1);
        //b-c+ab+c = (a+1)b
        long long kk = k+x;
        if(kk%(a+1)) return 0;
        else{
            long long b = kk/(a+1);
            long long c = b-k;
            if(b>0 && c>0) return 1;
            else return 0;
        }
    }
}

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
    long long x,y;
    scanf("%lld%lld",&x,&y);
    long long absDiff = x>y?x-y:y-x;
    long long ans = 0;
    //for a-1
    //a-1 == 0
    for(long long i = 1; i*i <= absDiff; i++){
        //printf("i = %lld\n",i);
        if(absDiff%i==0){
            ans += getCnt(i+1,x,y);
            if(absDiff/i!=i) ans += getCnt((absDiff/i)+1,x,y);
        }
    } 
    printf("%lld\n",ans);
}
    return 0;
}
0