题意:在1~n中选不超过m个数,求其异或最大值
题解:经过找规律发现如果m为1,输出n,不然输出最小的不超过n的2^k-1
C++ Code:
#include<cstdio> using namespace std; long long n,k,ans=1; int main(){ scanf("%I64d%I64d",&n,&k); if(k==1){ printf("%I64d ",n); }else{ while(n>>=1)ans<<=1; printf("%I64d ",(ans<<1)-1); } return 0; }