結果

問題 No.1243 約数加算
ユーザー KKT89KKT89
提出日時 2020-10-02 22:19:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 891 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 202,380 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 21:15:23
合計ジャッジ時間 2,887 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

const ll MX=1e18;

void print_res(vector<ll> res){
	printf("%d\n",res.size());
	for(ll p:res){
		printf("%lld ",p);
	}
	printf("\n");
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int q; cin >> q;
	while(q--){
		ll a,b;
		cin >> a >> b;
		// a=myRand(MX); b=myRand(MX);
		if(a>b)swap(a,b);
		vector<ll> res;
		ll p=1;
		while(b-a>0 and res.size()<120){
			while(a%p==0)p*=2;
			p/=2;
			if(b-a>=p){
				a+=p;
				res.push_back(p);
			}
			else{
				while(1){
					if((b-a)&p){
						a+=p;
						res.push_back(p);
						break;
					}
					else{
						p/=2;
					}
				}
			}
		}
		assert(a==b);
		assert(res.size()<=120);
		print_res(res);
	}
}
0