素数矩阵

素数矩阵

AcWing 3679
https://www.acwing.com/solution/content/53373/

构造题,答案不唯一

构造方法

每行每列都等于1

代码

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 110;

int T,n;


int main()
{
    cin >> T;
    while (T--)
    {
        cin >> n;
        for (int i = 0; i < n; i ++ )
        {
            for (int j = 0; j < n; j ++ )
            {
                if (i == j || (i + 1) % n == j) //(n,0)和(n,n+1)
                    cout << '1' << ' ';
                else
                    cout << '0' << ' ';
            }
            cout << endl;
        }
    }
    return 0;
}

posted @ 2021-06-18 16:21  Treasure_lee  阅读(178)  评论(0)    收藏  举报