結果
| 問題 |
No.1243 約数加算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-10-02 22:19:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 891 bytes |
| コンパイル時間 | 2,074 ms |
| コンパイル使用メモリ | 199,268 KB |
| 最終ジャッジ日時 | 2025-01-15 00:32:59 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
コンパイルメッセージ
main.cpp: In function ‘void print_res(std::vector<long long int>)’:
main.cpp:14:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
14 | printf("%d\n",res.size());
| ~^ ~~~~~~~~~~
| | |
| int std::vector<long long int>::size_type {aka long unsigned int}
| %ld
ソースコード
#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);
}
}