题解:P16337 「ALFR Round 10」Bit Problem

· · 题解

题意

题意简单,自己去看(逃……
注意,题目中的 \operatorname{and} 是按位与,不是逻辑与!

分析

不难发现,在进行一定次数的操作后,n 的值会保持不变,这时直接输出 n 即可。

代码

展示核心代码。

        cin>>n>>m>>k;
        for(int i=1;i<=k;++i){
            int nx=n&max(n-m,0);
            if(nx==n) break;
            n=nx;
        }
        cout<<n<<'\n';