Submission #1132682

#TimeUsernameProblemLanguageResultExecution timeMemory
1132682AgageldiNice sequence (IZhO18_sequence)C++17
15 / 100
4 ms836 KiB
/*
ID: agageld1
LANG: C++17
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define N 400005
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
#define rep(c, a, b) for(c = a; c <= b; c++)

ll n, t, T, a[N], m;

int main () {
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> T;
	while(T--) {
		cin >> n >> m;
		if(n == 1 && m == 1) {
			cout << "0\n";
			continue;
		}
		if(n%m == 0 || m%n == 0) {
			t = 1;
			if(m % n == 0) t = -1;
			cout << max(n,m) - 1<< '\n';
			for(int i = 1; i <= max(n,m) - 1; i++) {
				cout << t << ' ';
			}
			cout << '\n';
			continue;
		}
		if(n == 2) {
			cout << m << '\n';
			for(int i = 1; i < m; i += 2) {
				cout << m - 1 << " " << (-1) * m << ' ';
			}
			cout << m - 1 << '\n';
		}
		else {
			cout << n << '\n';
			for(int i = 1; i < n; i+=2) {
				cout << (n-1) * (-1) << " " << n << ' ';
			}
			cout << (n-1)* (-1) << '\n';
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...