結果
| 問題 |
No.1243 約数加算
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2020-10-02 22:32:42 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 767 bytes |
| コンパイル時間 | 605 ms |
| コンパイル使用メモリ | 69,856 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-17 22:06:47 |
| 合計ジャッジ時間 | 1,274 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
//約数列挙できないなあ…と思って、A=10^9+7, B=2A-1の例を考えていたら見えた。
//この問題、2進数の使い方が上手。
#include <iostream>
#include <vector>
#define int long long
using namespace std;
int T;
int a, b;
signed main() {
int i;
cin >> T;
while (T--) {
cin >> a >> b;
vector<int> ans;
while (a < b) {
int mul = 1;
while (a % mul == 0) {
mul *= 2;
}
mul /= 2;
if (a + mul <= b) {
ans.push_back(mul);
a += mul;
}
else {
while (a + mul > b) mul /= 2;
ans.push_back(mul);
a += mul;
}
}
cout << ans.size() << endl;
for (int i = 0; i < ans.size(); i++) {
cout << ans[i];
if (i + 1 < ans.size()) cout << " ";
}
cout << endl;
}
return 0;
}
startcpp