結果

問題 No.1243 約数加算
ユーザー fura
提出日時 2020-10-02 22:11:30
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 195,508 KB
最終ジャッジ日時 2025-01-15 00:25:18
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:9:24: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         lint a,b; scanf("%lld%lld",&a,&b);
      |                   ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:29:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |         int q; scanf("%d",&q); rep(_,q) solve();
      |                ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

void solve(){
	lint a,b; scanf("%lld%lld",&a,&b);

	int d;
	for(d=60;d>=0;d--) if((a>>d&1)!=(b>>d&1)) break;
	assert(d!=-1);

	vector<lint> ans;
	rep(i,d) if(a>>i&1) {
		a+=1LL<<i;
		ans.emplace_back(1LL<<i);
	}
	for(int i=d;i>=0;i--) if((a>>i&1)!=(b>>i&1)) {
		ans.emplace_back(1LL<<i);
	}

	printf("%ld\n",ans.size());
	rep(i,ans.size()) printf("%lld%c",ans[i],i+1<ans.size()?' ':'\n');
}

int main(){
	int q; scanf("%d",&q); rep(_,q) solve();
	return 0;
}
0