0%

The 2025 Shanghai Collegiate Programming Contest-G. 矩阵(gcd(a+bx,a)=gcd(a,b))

思路讲解

gcd(a,b)=gcd(ab,b)gcd(a, b) = gcd(a-b, b)

gcd(a+bx,a)=gcd(a,b)gcd(a+bx,a)=gcd(a,b)

使用如下构造方法即可。

1
2
3
4
5
6
7
8
9
10
11
12
inline void solve(){
cin>>N;
init();
sieve(N+40*N);
ll p= *upper_bound(all(primes),N);
FOR(i,1,N){
FOR(j,1,N){
cout<<i*p+j<<" ";
}
cout<<"\n";
}
}

AC代码

https://codeforces.com/gym/105992/my

心路历程(WA,TLE,MLE……)