/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 4000006;
int gcd(int a, int b)
{
if (!a || !b)
return a + b;
return gcd(b, a % b);
}
int lca(int a, int b)
{
return a / gcd(a, b) * b;
}
int q, n, m, k, a[N], used[N], tin[N];
vector<int> t, g[N];
void dfs(int v)
{
used[v] = 1;
for (int i = 0; i < g[v].size(); i++)
{
int to = g[v][i];
if (used[to])
continue;
dfs(to);
}
//tin[v] = -t.size();
t.PB(v);
}
void check(int x)
{
t.clear();
for (int i = 0; i <= x; i++)
g[i].clear();
for (int i = 0; i <= x; i++)
{
if (i - m >= 0)
g[i - m].PB(i);
if (i + n <= x)
g[i + n].PB(i);
}
for (int i = 0; i <= x; i++)
if (!used[i])
dfs(i);
int v, to;
for (int i = t.size() - 1; i >= 0; i--)
{
v = t[i];
a[v] = t.size() - i;
for (int j = 0; j < g[v].size(); j++)
{
to = g[v][j];
a[to] = a[v] + 1;
}
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> q;
while (q--)
{
k = 0;
cin >> n >> m;
k = n + m - gcd(n, m) - 1;
check(k);
cout << k << "\n";
for (int i = 1; i <= k; i++)
{
cout << (a[i] - a[i - 1]);
used[i] = 0;
}
used[0] = 0;
cout << "\n";
}
return 0;
}
/*
*/
Compilation message
sequence.cpp: In function 'void dfs(int)':
sequence.cpp:46:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < g[v].size(); i++)
~~^~~~~~~~~~~~~
sequence.cpp: In function 'void check(int)':
sequence.cpp:79:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j = 0; j < g[v].size(); j++)
~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
94328 KB |
Expected integer, but "-1-1" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
94332 KB |
Expected integer, but "-23-2" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
54 ms |
94328 KB |
Expected integer, but "2-32" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
94456 KB |
Expected integer, but "2-32" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
94328 KB |
Expected integer, but "-1-1" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
94328 KB |
Expected integer, but "-1-1" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
94328 KB |
Expected integer, but "-1-1" found |
2 |
Halted |
0 ms |
0 KB |
- |