Submission #3208300

Source Code Expand

Copy
```#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
vector<int> makePrimes(int n) { // [2,n]
vector<int> res, pr(n + 1, 1);
pr[0] = pr[1] = 0;
rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0;
rep(p, 2, n + 1) if (pr[p]) res.push_back(p);
return res;
}
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
/*---------------------------------------------------------------------------------------------------
∧＿∧
∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
（ ´_ゝ`）　/　 ⌒i
／　　　＼　 　 |　|
/　　 /￣￣￣￣/　　|
＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N;
ll ans[505][505];
//---------------------------------------------------------------------------------------------------
void _main() {
auto vp = makePrimes(51010);
cin >> N;

if (N == 2) {
printf("4 7\n23 10\n");
return;
}

rep(y, 0, N) rep(x, 0, N) if ((x + y) % 2 == 0) {
int u = (x + y) / 2;
int v = (x - y) / 2 + N / 2 + 1;

ans[y][x] = 1LL * vp[u] * vp[1010 - v];
}

rep(y, 0, N) rep(x, 0, N) if ((x + y) % 2 == 1) {
ll c = 1;
if (0 <= y - 1) c = lcm(c, ans[y - 1][x]);
if (y + 1 < N) c = lcm(c, ans[y + 1][x]);
if (0 <= x - 1) c = lcm(c, ans[y][x - 1]);
if (x + 1 < N) c = lcm(c, ans[y][x + 1]);
ans[y][x] = c + 1;
}

rep(y, 0, N) {
rep(x, 0, N) {
if (x) printf(" ");
printf("%lld", ans[y][x]);
}
printf("\n");
}
}```

#### Submission Info

Submission Time 2018-09-16 10:28:25+0900 D - Modulo Matrix hamayanhamayan C++14 (GCC 5.4.1) 1100 2548 Byte AC 59 ms 5176 KB

#### Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt
All 1100 / 1100 sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 512 KB
test_01.txt 59 ms 5176 KB
test_02.txt 58 ms 5176 KB
test_03.txt 1 ms 512 KB
test_04.txt 2 ms 512 KB
test_05.txt 1 ms 512 KB
test_06.txt 31 ms 3128 KB
test_07.txt 4 ms 824 KB