CodeForces - 1485D Multiples and Power Differences (构造+lcm)

简介: CodeForces - 1485D Multiples and Power Differences (构造+lcm)

CodeForces - 1485D Multiples and Power Differences (构造+lcm)

原题链接

思路:

考虑最特殊的情况:

b[i][j]=x=116lcm(x)

这样构造出来一定满足前两个条件。

至于第三个条件,可以将矩阵b按照奇偶分类,奇数时b[i] [j]的取值如上,偶数时b[i] [j]的取值要加上a[i] [j] 的四次方。这样对于任何一个数来说,第三个条件都是符合的。

代码:

#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;
}


目录
相关文章
|
18天前
|
Java
hdu-1016-Prime Ring Problem
hdu-1016-Prime Ring Problem
12 0
|
1月前
G - Prime Ring Problem(深搜)
G - Prime Ring Problem(深搜)
|
8月前
codeforces 317 A Perfect Pair
我先排除了输出-1的,然后再考虑如何计算最小的步数。我们主要在每一步中最小一个加上另一个就可以了,这是朴素的求法,但可能出现这样的情况 比如 -100000000 1 10000000 这样的话会循环100000000多次,肯定超时,所以我们要加快速度。
28 0
|
9月前
|
算法
The kth great number(小根堆思想,模板题)
The kth great number(小根堆思想,模板题)
28 0
The kth great number(小根堆思想,模板题)
|
10月前
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
UVa11296 - Counting Solutions to an Integral Equation(枚举技巧)
33 0
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
93 0
|
人工智能 BI
AtCoder Beginner Contest 216 F - Max Sum Counting (降维 背包dp)
AtCoder Beginner Contest 216 F - Max Sum Counting (降维 背包dp)
106 0
|
Perl
AtCoder Beginner Contest 217 F - Make Pair (区间dp)
AtCoder Beginner Contest 217 F - Make Pair (区间dp)
98 0
ICPC North Central NA Contest 2018 C . Rational Ratio(结论 模拟 gcd)
ICPC North Central NA Contest 2018 C . Rational Ratio(结论 模拟 gcd)
92 0

热门文章

最新文章