CodeForces - Múltiplos 1485D y diferencias de potencia (构造 + lcm)
Ideas:
Considere el caso más especial:
b [i] [j] = ∑ x = 1 16 lcm (x) b [i] [j] = \ sum_ {x = 1} ^ {16} {lcm (x)}b [ i ] [ j ]=x = 1∑1 6l c m ( x )
construido de esta manera debe satisfacer las dos primeras condiciones.
En cuanto a la tercera condición, la matriz b se puede clasificar de acuerdo con la paridad. Cuando el número es impar, el valor de b [i] [j] es igual que el anterior, y cuando el número es par, el valor de b [i] [j] debe agregarse con un [i] [j] a la cuarta potencia. Entonces, para cualquier número, se cumple la tercera condición.
Código:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;typedef unsigned long long ull;
typedef pair<ll,ll>PLL;typedef pair<int,int>PII;typedef pair<double,double>PDD;
#define I_int ll
inline ll read(){
ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';ch=getchar();}return x*f;}
ll ksm(ll a,ll b,ll p){
ll res=1;while(b){
if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
const int maxn=1e6+7;
int a[510][510],b[510][510];
int gcd(int a,int b){
return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b){
return a/gcd(a,b)*b;
}
void solve(){
int n=read(),m=read();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
a[i][j]=read();
int t=1;
for(int i=2;i<=16;i++)
t=lcm(t,i);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++)
if((i+j)%2) cout<<t<<" ";
else cout<<t+a[i][j]*a[i][j]*a[i][j]*a[i][j]<<" ";
puts("");
}
}
int main(){
int T=1;
while(T--) solve();
return 0;
}