More than 2019 cattle off summer school camp (fourth) - triples I

thinking

If only two bits is not a multiple of 1 and 3 is clearly not the answer, we only consider two or more cases.

  • If a mod 3 = 1:
  • If a bit in at least two mod 3 = 1, and they are provided p and q, we get {ap, aq} can.
  • If a binary bit just a mod 3 = 1, then this bit is set mod 3 = 1 to P, a bit mod 3 = 2 for q, we get {ap, p + q} can.
  • If the bit is not a mod 3 = 1, then there are assumed three mod 3 = 2 bits p, q, r, we take {a- pq, p + q + r} can.
  • If only a mod 3 = 2 to 1 and discussed above can exchange 2, it is completely symmetrical.
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define full(a, b) memset(a, b, sizeof a)
#define FastIn ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long LL;
inline int lowbit(int x){ return x & (-x); }
inline int read(){
    int ret = 0, w = 0; char ch = 0;
    while(!isdigit(ch)){
        w |= ch == '-', ch = getchar();
    }
    while(isdigit(ch)){
        ret = (ret << 3) + (ret << 1) + (ch ^ 48);
        ch = getchar();
    }
    return w ? -ret : ret;
}
inline int lcm(int a, int b){ return a / __gcd(a, b) * b; }
template <typename A, typename B, typename C>
inline A fpow(A x, B p, C lyd){
    A ans = 1;
    for(; p; p >>= 1, x = 1LL * x * x % lyd)if(p & 1)ans = 1LL * x * ans % lyd;
    return ans;
}

int main(){

    int _;
    LL n;
    for(scanf("%d", &_); _; _ --){
        scanf("%lld", &n);
        if(n % 3 == 0){
            printf("1 %lld\n", n);
            continue;
        }
        vector<LL> a, b, c;
        LL x = n;
        while(x) a.push_back(x & 1), x >>= 1;
        LL val = 1;
        for(int i = 0; i < a.size(); i ++){
            if(a[i]){
                if(val % 3 == 1) b.push_back(val);
                if(val % 3 == 2) c.push_back(val);
            }
            val <<= 1;
        }
        if(n % 3 == 1){
            if(b.size() >= 2) printf("2 %lld %lld\n", n - b[0], n - b[1]);
            else if(b.size() == 1) printf("2 %lld %lld\n", n - b[0], b[0] + c[0]);
            else printf("2 %lld %lld\n", n - c[0] - c[1], c[0] + c[1] + c[2]);
        } else{
            if(c.size() >= 2) printf("2 %lld %lld\n", n - c[0], n - c[1]);
            else if(c.size() == 1) printf("2 %lld %lld\n", n - c[0], c[0] + b[0]);
            else printf("2 %lld %lld\n", n - b[0] - b[1], b[0] + b[1] + b[2]);
        }
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/onionQAQ/p/11260838.html