제출 #1132694

#제출 시각아이디문제언어결과실행 시간메모리
1132694AgageldiNice sequence (IZhO18_sequence)C++17
6 / 100
0 ms328 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';
			continue;
		}
		if(n%2 == 0) {
			cout <<"0\n";
			continue;
		}
		if(n < m) {
			cout << "-1 ";
			for(int i = 1; i < m; i += 2) {
				cout << n << " " << (-1) * n << ' ';
			}
			cout << n << " " << "-1\n";
		}
		else {
			cout << "1 ";
			for(int i = 1; i < n; i += 2) {
				cout << (-1) * m  << " " << m << " ";
			}
			cout << (-1)*m << " " << "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...