結果
| 問題 |
No.1243 約数加算
|
| コンテスト | |
| ユーザー |
srjywrdnprkt
|
| 提出日時 | 2024-04-09 14:17:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 912 bytes |
| コンパイル時間 | 2,282 ms |
| コンパイル使用メモリ | 195,548 KB |
| 最終ジャッジ日時 | 2025-02-20 23:21:35 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(){
// 010100110
// 010101000
// 010110000
// 011000000
// 100000000
// 100101011
ll A, B;
cin >> A >> B;
vector<ll> ans;
//1,Bの最上位以外のbitを0にする(下から)
for (int i=0; i<60; i++){
if ((A>>i & 1) && A+(1LL<<i)<=B){
A += (1LL<<i);
ans.push_back((1LL<<i));
}
}
//2,Bと立っているbitを揃える(上から)
for (int i=59; i>=0; i--){
if ((B>>i & 1) && !(A>>i & 1)){
A += (1LL<<i);
ans.push_back((1LL<<i));
}
}
assert(A == B);
cout << ans.size() << endl;
for (auto x : ans) cout << x << " ";
cout << endl;
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int T;
cin >> T;
while(T--) solve();
return 0;
}
srjywrdnprkt