#4508. Triples I

Title Description

Known $ A $, you can choose the number $ m $, $ are satisfied for each number multiple of $ 3 and $ m $ or the number of $ a $.

Again minimizing $ m $.

data range

The data of $ 100 \% of $, $ T \ le 10 ^ 5 $, $ a \ le 10 ^ {18} $.

answer

Emergent of a problem

If a multiple of $ $ $ A $ 3, then the $ A $ can be used directly

Number up or otherwise consider the possibility of using two $ 3 $ multiples of $ a $

The $ A $ split position, apparently $ 2 ^ i \% 3 = 1/2 $, so the $ \% 3 $ to $ 1 $ and $ \% 3 $ to $ 2 $ separated position, then more than that take the side two numbers together, so that can be placed on the other side, the above operation is repeated until the difference between both sides can not exceed $ 1 $

Code

#include <bits/stdc++.h>
#define _(d) while(d(isdigit(c=getchar())))
typedef long long LL;using std::swap;
LL R(){char c;_(!);LL x=c^48;_()x=(x<<3)+(x<<1)+(c^48);return x;}
int T,t[2],m,u,v;LL a,p[2][65],x,y,j;
int main(){
    for (scanf("%d",&T);T--;){
        a=R();
        if (a%3==0){printf("1 %lld\n",a);continue;}
        j=1;t[0]=t[1]=0;
        for (int i=0;j<=a;i++,j<<=1)
            if (a&j) p[i&1][++t[i&1]]=j;
        u=0;v=1;if (t[0]>t[1]) swap(u,v);
        while(t[v]-t[u]>1)
            p[u][++t[u]]=p[v][t[v]]|p[v][t[v]-1],t[v]-=2;
        u=0;v=1;if (t[0]>t[1]) swap(u,v);
        x=0,y=0;for (int i=1;i<=t[u];i++)
            x|=(p[u][i]|p[v][i]),y|=(p[u][i]|p[v][i+1]);
        printf("2 %lld %lld\n",x,y);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/xjqxjq/p/11370163.html