結果

問題 No.1243 約数加算
ユーザー DriceDrice
提出日時 2020-10-02 22:35:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 31,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 21:49:32
合計ジャッジ時間 1,103 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
long long ans[125];

int main(){
    int T;
    scanf("%d",&T);
    while(T--){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    long long diff = b-a;
    //can use for now
    long long base = 1;
    int size = 0;
    while(base<=diff){
        long long nBase = base*2;
        if(a%nBase){
            diff -= base;
            a += base;
            ans[++size] = base;
        }
        base *= 2;
    }
    int tag = size;
    int len = 0;
    while(diff!=0){
        if(diff%2) ans[++size] = 1ll<<len;
        len++;
        diff /= 2;
    }
    printf("%d\n",size);
    for(int i = 1; i <= tag; i++) printf("%lld ",ans[i]);
    for(int i = size; i > tag; i--) printf("%lld ",ans[i]);
    printf("\n");
}
    return 0;
}
0