1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 #include #include #include #include #include using namespace std; using int64 = long long; int64 numberOfPairs(int64 n) { return (n-1)*n/2; } bool isNO(int64 pairs) { return pairs%2 != 0; } bool checkIfCorrectPairs(const std::vector& vec, int64 reqPairs) { int64 found = 0; std::set v; for (int64 i = 0;i solution(int64 N, int64 K, int64 reqPairs) { std::vector vec(N); int n=0; int p=1; std::generate(vec.begin(), vec.end(), [&p] () { return p++; }); do { if (checkIfCorrectPairs(vec, reqPairs)) { n++; } if (n == K) return vec; } while(std::next_permutation(vec.begin(), vec.end())); return {}; } int main() { int64 N = 0; int64 K = 0 ; scanf("%lld", &N); scanf("%lld", &K); if (isNO(numberOfPairs(N))){ cout << "NIE" << endl; return 1; } int64 requiredPairs = numberOfPairs(N)/2; auto solutionRes = solution(N,K,requiredPairs); if (solutionRes.empty()){ cout << "NIE" << endl; return 1; } cout << "TAK" << endl; for (auto p : solutionRes) { cout << p << " "; } cout << endl; return 0; }