![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmath> 5 #include<cstdlib> 6 using namespace std; 7 8 bool judge(int s) 9 { 10 int k = sqrt(s); 11 return k*k == s; 12 } 13 int main() 14 { 15 int n,m; 16 int a,b,c,d; 17 scanf("%d%d",&n,&m); 18 while (true) 19 { 20 a = rand()%100 + 1; 21 b = rand()%100 + 1; 22 c = rand()%100 + 1; 23 d = rand()%100 + 1; 24 if (judge(a*a*(m-1) + b*b) 25 &&judge(a*a*(n-1)+c*c) 26 &&judge(b*b*(n-1)+d*d) 27 &&judge(c*c*(m-1)+d*d)) 28 break; 29 } 30 for (int i = 1;i<n;i++) 31 { 32 for (int j = 1;j<m;j++) 33 printf("%d ",a); 34 printf("%d ",b); 35 } 36 for (int i = 1;i<m;i++) 37 printf("%d ",c); 38 printf("%d ",d); 39 return 0; 40 }
随机构造