Codeforces 1485D - Multiples and Power Differences

写写构造题。
链接:https://codeforces.com/contest/1485/problem/D
题意,给定n*m大小矩阵A,求矩阵B,满足a[i][j] | b[i][j] && 两相邻格差值为四次方数(不为0),给出构造。
n,m<=500,a[i][j]<=16.
由于a[i][j]很小,考虑其所有数的lcm,为2^4 * 3 ^2 * 5 * 7 * 11 * 13=720720.
故考虑按照棋盘划分格子,黑格子放lcm,白格子放lcm+对应a[i][j]^4,此时易知满足题意。
代码:

#define int long long
using namespace std;
int a[600][600],b[600][600];
int w=720720;
signed main(){
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if((i+j)%2==0){
				b[i][j]=w;
			}
			else{
				int k=a[i][j];
				b[i][j]=w+k*k*k*k;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
		cout<<b[i][j]<<" ";
		cout<<endl;
	}
}
posted @ 2023-01-25 11:31  wrong,anser  阅读(21)  评论(0)    收藏  举报