B. Magical Palette

  • 你说的对,此题的数论背景很复杂,甚至连jiangly老师可能都不太会完整的证明;但所幸作为做题者,你不需要完成证明,只需要给出构造方案
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		if(__gcd(n,m)==1)
		{
			cout<<"Yes\n";
			if(n==1&&m==1)
			{
				cout<<"0\n";
				cout<<"0\n";
			}
			else if(n==1)
			{
				cout<<1<<"\n";
				for(int j=0;j<m;j++)
				{
					cout<<j<<" ";
				}
				cout<<"\n";
			}
			else if(m==1)
			{
				for(int i=0;i<n;i++)
				{
					cout<<i<<" ";
				}
				cout<<"\n";
				cout<<1<<"\n";
			}
			else
			{
				for(int i=0;i<n;i++)
				{
					cout<<i*m+1<<" ";
				}
				cout<<"\n";
				for(int j=0;j<m;j++)
				{
					cout<<j*n+1<<" ";
				}
				cout<<"\n";
			}
		}
		else
		{
			cout<<"No\n";
		}
	} 
	return 0;
}
posted @ 2025-01-30 21:25  D06  阅读(77)  评论(0)    收藏  举报
//雪花飘落效果