#include #ifdef LOCAL #include #else #define debug(...) void(0) #endif using namespace std; typedef long long ll; #define all(x) begin(x), end(x) constexpr int INF = (1 << 30) - 1; constexpr long long IINF = (1LL << 60) - 1; constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; template istream& operator>>(istream& is, vector& v) { for (auto& x : v) is >> x; return is; } template ostream& operator<<(ostream& os, const vector& v) { auto sep = ""; for (const auto& x : v) os << exchange(sep, " ") << x; return os; } template bool chmin(T& x, U&& y) { return y < x and (x = forward(y), true); } template bool chmax(T& x, U&& y) { return x < y and (x = forward(y), true); } template void mkuni(vector& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } template int lwb(const vector& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); } /* 1 から N で最大の素数 p lcm(p, x) は x = 1, p のときのみ p でそれ以外は px */ int N; vector A, B; int query(int i, int j) { assert(0 <= i and i < N); assert(0 <= j and j < N); cout << "? " << i + 1 << ' ' << j + 1 << endl; int res; #ifdef LOCAL res = lcm(A[i], B[j]); #else cin >> res; #endif return res; } void answer(vector a, vector b) { cout << '!'; for (int& x : a) cout << ' ' << x; for (int& x : b) cout << ' ' << x; cout << endl; #ifdef LOCAL assert(a == A and b == B); #endif } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N; #ifdef LOCAL A.resize(N); B.resize(N); iota(all(A), 1); iota(all(B), 1); random_device seed_gen; mt19937 engine(seed_gen()); shuffle(all(A), engine); shuffle(all(B), engine); debug(A, B); #endif vector A(N, -1), B(N, -1); if (N == 1) { A[0] = B[0] = 1; answer(A, B); return 0; } vector is_prime(N + 1, true); int p = -1; for (int i = 2; i <= N; i++) { if (not is_prime[i]) continue; p = i; for (int j = i + i; j <= N; j += i) is_prime[j] = false; } vector C(N); for (int i = 0; i < N; i++) C[i] = query(0, i); A[0] = *min_element(all(C)); debug(C, A[0]); int pos = -1; if (A[0] == p) { pos = 0; vector cand; for (int i = 0; i < N; i++) { if (C[i] == p) cand.emplace_back(i); else B[i] = C[i] / p; } assert(int(cand.size()) == 2); vector D(N); for (int i = 0; i < N; i++) D[i] = query(i, cand[0]); B[cand[0]] = *min_element(all(D)); B[cand[1]] = 1 + p - B[cand[0]]; int one = -1; for (int i = 0; i < 2; i++) { if (B[cand[i]] == 1) { one = cand[i]; } } assert(one != -1); debug(one); for (int i = 1; i < N; i++) A[i] = query(i, one); } else { for (int i = 0; i < N; i++) { if (C[i] == A[0] * p) { assert(pos == -1); pos = i; } } assert(pos != -1); B[pos] = p; vector D(N), cand; for (int i = 0; i < N; i++) { D[i] = query(i, pos); if (D[i] == p) cand.emplace_back(i); else A[i] = D[i] / p; } assert(int(cand.size()) == 2); if (query(cand[0], (pos + 1) % N) % p == 0) A[cand[0]] = p; else A[cand[0]] = 1; A[cand[1]] = 1 + p - A[cand[0]]; debug(cand, A); int one = -1; for (int i = 0; i < 2; i++) { if (A[cand[i]] == 1) { one = cand[i]; } } assert(one != -1); debug(one); for (int i = 0; i < N; i++) { if (B[i] != -1) continue; B[i] = query(one, i); } } answer(A, B); return 0; }