//Challenge: Accepted
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
#include <utility>
#include <assert.h>
using namespace std;
void debug() {cout << endl;}
template <class T, class ...U> void debug(T a, U ... b) { cout << a << " "; debug(b...);}
template <class T> void pary(T l, T r) {
while (l != r) {cout << *l << " ";l++;}
cout << endl;
}
#define ll long long
#define ld long double
#define maxn 100005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int flip = 0;
void solve(int n, int m, vector<bool> &res) {
int rev = 0;
if (n > m) swap(n, m), rev = 1; //(assuming n <= m)
if (m % n == 0) { // ans = m - 1
for (int i = 0;i < m - 1;i++) {
if (n != 1 && i % n == n - 1) res.push_back(1);
else res.push_back(0);
}
} else {
solve(n, m - n, res);
for (int i = 0;i < n;i++) {
res.push_back((res.size() >= n ? res[res.size() - n] : 0));
}
}
if (rev) {
for (int i = 0;i < res.size();i++) res[i] = (res[i] ? 0 : 1);
}
//debug(n, m);
//pary(res.begin(), res.end());
}
int main() {
io
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<bool> ans;
solve(n, m, ans);
cout << ans.size() << endl;
ll cn = 0, cm = 0, an = 0, am = 0;
if (n % m == 0 || m % n == 0) {
an = -1, am = 1;
} else {
for (int i = 0;i < n;i++) cn += ans[i] == 0 ? 1 : 0;
for (int i = 0;i < m;i++) cm += ans[i] == 0 ? 1 : 0;
am = 8e7;
ll lb = (ll)(cm - m) * am / cm, rb = (ll)(cn - n) * am/ cn;
an = (lb + rb) / 2;
}
for (int i = 0;i < ans.size();i++) {
cout << (ans[i] ? am : an) << " ";
}
cout << endl;
}
}
Compilation message
sequence.cpp: In function 'void solve(int, int, std::vector<bool>&)':
sequence.cpp:38:30: warning: comparison of integer expressions of different signedness: 'std::vector<bool>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
38 | res.push_back((res.size() >= n ? res[res.size() - n] : 0));
| ~~~~~~~~~~~^~~~
sequence.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 0;i < res.size();i++) res[i] = (res[i] ? 0 : 1);
| ~~^~~~~~~~~~~~
sequence.cpp: In function 'int main()':
sequence.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for (int i = 0;i < ans.size();i++) {
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
312 KB |
Ok |
5 |
Correct |
1 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
316 KB |
Ok |
8 |
Correct |
1 ms |
204 KB |
Ok |
9 |
Correct |
1 ms |
256 KB |
Ok |
10 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
312 KB |
Ok |
5 |
Correct |
1 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
316 KB |
Ok |
8 |
Correct |
1 ms |
204 KB |
Ok |
9 |
Correct |
1 ms |
256 KB |
Ok |
10 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
312 KB |
Ok |
5 |
Correct |
1 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
316 KB |
Ok |
8 |
Correct |
1 ms |
204 KB |
Ok |
9 |
Correct |
1 ms |
256 KB |
Ok |
10 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Ok |
2 |
Correct |
1 ms |
204 KB |
Ok |
3 |
Correct |
1 ms |
204 KB |
Ok |
4 |
Correct |
1 ms |
312 KB |
Ok |
5 |
Correct |
1 ms |
204 KB |
Ok |
6 |
Correct |
1 ms |
204 KB |
Ok |
7 |
Correct |
1 ms |
316 KB |
Ok |
8 |
Correct |
1 ms |
204 KB |
Ok |
9 |
Correct |
1 ms |
256 KB |
Ok |
10 |
Incorrect |
1 ms |
204 KB |
there is incorrect sequence |
11 |
Halted |
0 ms |
0 KB |
- |