[atARC140E]Not Equal Rectangle

取$P=23$,构造$A_{i,j}=(\lfloor\frac{i}{P}\rfloor\lfloor\frac{j}{P}\rfloor+i+j)mod\ P+1$($i$和$j$均从0开始)

关于正确性,证明如下——

考虑同列的两数,代入得$A_{i_{1},j}=A_{i_{2},j}$当且仅当$(\lfloor\frac{i_{2}}{P}\rfloor-\lfloor\frac{i_{1}}{P}\rfloor)\lfloor\frac{j}{P}\rfloor\equiv i_{2}-i_{1}(mod\ P)$

结合$P^{2}\ge n$,当$\lfloor\frac{i_{1}}{P}\rfloor\equiv \lfloor\frac{i_{2}}{P}\rfloor(mod\ P)$时,简单分析可得$i_{1}=i_{2}$,矛盾

结合$P$是素数,$\lfloor\frac{i_{2}}{P}\rfloor-\lfloor\frac{i_{1}}{P}\rfloor$存在模$P$的逆元,进而条件也即$\lfloor\frac{j}{P}\rfloor\equiv f(i_{1},i_{2})(mod\ P)$

关于限制,即存在$j_{1}$和$j_{2}$均满足上式,进而$\lfloor\frac{j_{1}}{P}\rfloor\equiv \lfloor\frac{j_{2}}{P}\rfloor$,同理可得$j_{1}=j_{2}$,矛盾

综上,即得证

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define P 23
 4 int n,m;
 5 int main(){
 6     scanf("%d%d",&n,&m);
 7     for(int i=0;i<n;i++){
 8         for(int j=0;j<m;j++)printf("%d ",((i/P)*(j/P)+i+j)%P+1);
 9         printf("\n");
10     }
11     return 0;
12 }
View Code

 

posted @ 2022-05-16 16:16  PYWBKTDA  阅读(137)  评论(1编辑  收藏  举报