C. Meaningless Operations

 http://codeforces.com/contest/1110/problem/C

题意:q个询问,每个询问a,问1~a-1,内求max(   gcd(a^b,a&b)  );

思路:但a的二进制的位置有0是就是gcd(0,2^cnt-1),a二进制有cnt位;全是1时,有a&b=b,a^b=a-a&b=a-b;即gcd(a-b,b),即

gcd(a,b),即2^cnt-1的最大因子;

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

#define sfi(i) scanf("%d",&i)
#define pri(i) printf("%d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-6
#define PI acos(-1)
#define lowbit(x) ((x)&(-x))
#define zero(x) (((x)>0?(x):-(x))
inline void sc(T &ret)
{
    char c;
    ret = 0;
    while ((c = getchar()) < '0' || c > '9');
    while (c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0'), c = getchar();
    }
}

ll power(ll x,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*x;
        x=x*x;
        n>>=1;
    }
    return ans;
}

int main()
{
    int q;
    cin>>q;
    while(q--)
    {
        int x;
        cin>>x;
        bool f=0;
        ll ans=0;
        int cnt=0;
        while(x)
        {
            cnt++;
            if(x%2==0)
            {
                f=1;
            }
            x>>=1;
        }
        if(f)
        {
            cout<

 

你可能感兴趣的:(C. Meaningless Operations)