Rút Bài Đầu Xuân

 avatar
unknown
c_cpp
2 months ago
899 B
8
Indexable
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
    for (int i=2; i*i<=n; i++)
        if (n%i == 0)
            return false;
    return true;
}

int p[35];

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0);


    for (int i = 30; i >= 2; i--) {

        int x = (1<<i)+1;
        while (!isPrime(x)) x+=2;

        p[i] = x;
    }

    int tc; cin >> tc;
    while (tc--) {
        int n; cin >> n;
        vector<int> ans;
        for (int i = 30; i >= 2; --i) {
            if (n >= (1 << i)) {
                n ^= p[i];
                ans.push_back(p[i]);
            }
        }
        if (n == 2 || n == 3) ans.push_back(n);
        else if (n == 1) {
            ans.push_back(2);
            ans.push_back(3);
        }
        for (auto i : ans) cout << i << ' ';
        cout << '\n';
    }


    return 0;
}
Editor is loading...
Leave a Comment