Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- vector<int> perm;
- int cnt;
- ll n;
- int query(int i, int j) {
- if (++cnt > 2 * n) {
- cout << ("query limit") << '\n';
- exit(0);
- }
- if (i == j)
- exit(130);
- return __gcd(perm[i], perm[j]);
- }
- void answer(vector<int> ans) {
- sort((ans).begin(), (ans).end());
- if (ans.size() != 2)
- exit(131);
- if (perm[ans[0]] != 0 && perm[ans[1]] != 0) {
- for (auto i : perm) cout << i << ' ';
- exit(1);
- }
- }
- int main() {
- n = 10;
- perm = vector<int>(n);
- iota((perm).begin(), (perm).end(), 0);
- do {
- cnt = 0;
- vector<int> possible(n), ans;
- iota((possible).begin(), (possible).end(), 0);
- while (possible.size() > 2) {
- vector<int> res;
- res.push_back(-1);
- for (int i = 1; i < possible.size(); i++) {
- res.push_back(query(possible[i], possible[0]));
- }
- int mx = *max_element((res).begin(), (res).end());
- vector<int> next;
- for (int i = 0; i < possible.size(); i++) {
- if (res[i] == mx)
- next.push_back(possible[i]);
- }
- if (next.size() == 1) {
- next.push_back(possible[0]);
- }
- possible = next;
- }
- answer(possible);
- } while (next_permutation((perm).begin(), (perm).end()));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement