constint N = 2e5 + 5; constdouble eps = 1e-6; constexprint mod = 1e9 + 7; constexprint i32 = 0x3f3f3f3f;
using vi = vector<int>; using vvi = vector<vi>;
intmain(){ fastIO(); int n, m; cin >> n >> m;
std::vector<std::pair<int, int>> shifts; for (int i = -n; i < n; i++) { for (int j = -n; j < n; j++) { if (i * i + j * j == m) { shifts.emplace_back(i, j); } } }
std::vector<std::vector<int>> d(n, vector<int>(n, -1)); d[0][0] = 0; std::vector<std::pair<int, int>> que; que.emplace_back(0, 0); for (int b = 0; b < (int) que.size(); b++) { for (auto &s: shifts) { int ni = que[b].first + s.first; int nj = que[b].second + s.second; if (ni >= 0 && nj >= 0 && ni < n && nj < n && d[ni][nj] == -1) { que.emplace_back(ni, nj); d[ni][nj] = d[que[b].first][que[b].second] + 1; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << d[i][j] << " \n"[j == n - 1]; } } return0; }
constint N = 2e5 + 5; constdouble eps = 1e-6; constexprint mod = 1e9 + 7; constexprint i32 = 0x3f3f3f3f;
using vi = std::vector<int>; using vvi = std::vector<vi>;
intmain(){ fastIO(); int n, m; cin >> n >> m; std::vector<int> a(n); put(a);
std::vector<std::vector<int>> at(m); for (int i = 0; i < n; i++) { int k = 0; if (a[i] < 0) { k = max(k, (-a[i] - 1) / (i + 1)); } while (k < m && a[i] + (i + 1) * (k + 1) < n) { at[k].push_back(a[i] + (i + 1) * (k + 1)); k += 1; } } for (int i = 0; i < m; i++) { sort(at[i].begin(), at[i].end()); int res = 0; for (int x : at[i]) { if (x == res) { res += 1; } } cout << res << "\n"; } return0; }
ll f(ll k){ ll cnt = 0, c = 0, d = 0; longdouble a = k / 2, b = k / 3; if (mem.count(a)) { tot += mem[a]; c = mem[a]; } elseif (a < 0.5) { c = f(0); tot += c; } else c = f((ll) a);
mem[a] = c;
if (mem.count(b)) { tot += mem[b]; d = mem[b]; } elseif (b < 0.5) { d = f(0); tot += d; } else d = f((ll) b);