题目链接:
代码如下:
#include <bits/stdc++.h>
using namespace std;
const int maxn=5205;
int n;
string a[maxn];
int Judge (int x)
{
for (int i=0;i<n;i+=x)
{
for (int j=0;j<n;j+=x)
{
char t=a[i][j];
for (int k=i;k<i+x;k++)
{
for (int l=j;l<j+x;l++)
{
if(a[k][l]!=t)
return 0;
}
}
}
}
return 1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for (int i=0;i<n;i++)
{
string s;
cin>>s;
for (int j=0;j<s.size();j++)
{
if(s[j]=='0')
{
a[i]+="0000";
}
else if(s[j]=='1')
{
a[i]+="0001";
}
else if(s[j]=='2')
{
a[i]+="0010";
}
else if(s[j]=='3')
{
a[i]+="0011";
}
else if(s[j]=='4')
{
a[i]+="0100";
}
else if(s[j]=='5')
{
a[i]+="0101";
}
else if(s[j]=='6')
{
a[i]+="0110";
}
else if(s[j]=='7')
{
a[i]+="0111";
}
else if(s[j]=='8')
{
a[i]+="1000";
}
else if(s[j]=='9')
{
a[i]+="1001";
}
else if(s[j]=='A')
{
a[i]+="1010";
}
else if(s[j]=='B')
{
a[i]+="1011";
}
else if(s[j]=='C')
{
a[i]+="1100";
}
else if(s[j]=='D')
{
a[i]+="1101";
}
else if(s[j]=='E')
{
a[i]+="1110";
}
else if(s[j]=='F')
{
a[i]+="1111";
}
}
}
int ans;
for (int i=1;i<=n;i++)
{
if(n%i==0)
{
if(Judge(i))
{
ans=i;
}
}
}
cout<<ans;
return 0;
}