题意:在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",n);
    }else{
    	while(n>>=1)ans<<=1;
	    printf("%I64d\n",(ans<<1)-1);  
	}
    return 0;  
}

 

相关文章:

  • 2021-07-11
  • 2021-05-17
  • 2021-10-13
  • 2021-07-20
  • 2021-08-26
  • 2021-05-04
猜你喜欢
  • 2021-06-10
  • 2022-01-17
  • 2022-01-21
  • 2021-09-07
  • 2022-12-23
  • 2022-01-27
  • 2021-07-07
相关资源
相似解决方案