1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include<bits/stdc++.h> using namespace std; #define ll long long const int N = 5210; string str[16]={"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"}; char s[N][N]; bool martix[N][N]; int pre[N][N]; int n; int getnum(char c){ if(c>='0'&&c<='9')return c-'0'; else return c-'A'+10; } int judge(int x1,int y1,int x2,int y2){ return pre[x2][y2]+pre[x1-1][y1-1]-pre[x1-1][y2]-pre[x2][y1-1]; } bool check(int k){ for(int i=1;i<=n;i+=k){ if(i+k-1>n)break; for(int j=1;j<=n;j+=k){ if(j+k-1>n)break; if(judge(i,j,i+k-1,j+k-1)!=k*k&&judge(i,j,i+k-1,j+k-1)!=0)return false; } } return true; } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%s",s[i]+1); int ans = 1; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ int l = ceil(1.0*j/4); int pos = getnum(s[i][l]); martix[i][j]=str[pos][j%4==0?3:j%4-1]-'0'; } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+martix[i][j]; } } int sn =sqrt(n)+1; for(int i=n;i>=2;i--){ if(n%i==0&&check(i)){ ans=i; break; } } printf("%d\n",ans); }
|