fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5.  
  6. void Anas() {
  7. int n,m; cin >> n >> m;
  8. int mn = min(n,m);
  9. mn = 1<<mn;
  10. // cout << mn;
  11. int mx = max(n,m);
  12. mn = min(mn,mx);
  13. cout << mn <<"\n";
  14. if(m >= n){
  15. int cnt = 1;
  16. for(int i = 1; i <= n; i++){
  17. for(int j = 1; j <= cnt; j++){
  18. cout << "1" <<" ";
  19. }
  20. int x = 2;
  21. for(int j = 1; j <= (m - cnt); j++){
  22. cout << x <<" ";
  23. x++;
  24. }
  25. cnt++;
  26. cout <<"\n";
  27. }
  28. return;
  29. }
  30. for(int i = 1; i <= n; i++){
  31. int x = i;
  32. for(int j = 1; j <= m; j++){
  33. if(x == 1){
  34. cout << 1 <<" ";
  35. continue;
  36. }
  37. cout << x <<" ";
  38. x--;
  39. }
  40. cout <<"\n";
  41. }
  42. }
  43.  
  44. int32_t main() {
  45. ios::sync_with_stdio(false);
  46. cin.tie(NULL);
  47.  
  48. int test = 1;
  49. cin >> test;
  50.  
  51. while (test--) {
  52. Anas();
  53. }
  54.  
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
1