B. New Year's Eve
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.

The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!

A xor-sum of a sequence of integers a1, a2, ..., am is defined as the bitwise XOR of all its elements: , here denotes the bitwise XOR operation; more about bitwise XOR can be found here.

Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.

Input
The sole string contains two integers n and k (1 ≤ k ≤ n ≤ 1018).

Output
Output one number — the largest possible xor-sum.

Input

 

Output


思路

题意:从1~n中选出k个数,使得它们的异或值最大

解题思路:可以发现从了k等于1的时候答案为n,否则一定有使n的所有位为1的数。

AC代码:

#include<bits/stdc++.h>

using namespace std;

#define int  unsigned long long

signed main(){
int n,k;
cin>>n>>k;
if(k==){
cout<<n;return ;
}
int cnt=;
while(n){
cnt++;
n/=;
}
cout<<(int)(pow(,cnt))-;
return ;
}
/*
1 0
2 1
4 2
8 3
16 4 */

Codeforces Round #456 (Div. 2) B题的更多相关文章

  1. Codeforces Round #378 (Div. 2) D题(data structure)解题报告

    题目地址 先简单的总结一下这次CF,前两道题非常的水,可是第一题又是因为自己想的不够周到而被Hack了一次(或许也应该感谢这个hack我的人,使我没有最后在赛后测试中WA).做到C题时看到题目情况非常 ...

  2. Codeforces Round #456 (Div. 2)

    Codeforces Round #456 (Div. 2) A. Tricky Alchemy 题目描述:要制作三种球:黄.绿.蓝,一个黄球需要两个黄色水晶,一个绿球需要一个黄色水晶和一个蓝色水晶, ...

  3. Codeforces Round #612 (Div. 2) 前四题题解

    这场比赛的出题人挺有意思,全部magic成了青色. 还有题目中的图片特别有趣. 晚上没打,开virtual contest打的,就会前三道,我太菜了. 最后看着题解补了第四道. 比赛传送门 A. An ...

  4. Codeforces Round #713 (Div. 3)AB题

    Codeforces Round #713 (Div. 3) Editorial 记录一下自己写的前二题本人比较菜 A. Spy Detected! You are given an array a ...

  5. Codeforces Round #552 (Div. 3) A题

    题目网址:http://codeforces.com/contest/1154/problem/ 题目意思:就是给你四个数,这四个数是a+b,a+c,b+c,a+b+c,次序未知要反求出a,b,c,d ...

  6. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  7. Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)

    题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...

  8. Codeforces Round #425 (Div. 2))——A题&&B题&&D题

    A. Sasha and Sticks 题目链接:http://codeforces.com/contest/832/problem/A 题目意思:n个棍,双方每次取k个,取得多次数的人获胜,Sash ...

  9. Codeforces Round #456 (Div. 2) B. New Year's Eve

    传送门:http://codeforces.com/contest/912/problem/B B. New Year's Eve time limit per test1 second memory ...

随机推荐

  1. 2019.08.02 云从科技C++后台开发

    公司坐标:重庆 岗位:C++后台开发 面试时长:45分钟 主要问题记录: (1)手写代码 冒泡算法的实现: /**   * 冒泡排序:C++   *   * @author skywang   * @ ...

  2. python — 表的操作(一)

    1. 创建表 创建表: create table t1 (id int,name char(4)); create table t2 (id int,name char(4)) engine=myis ...

  3. python — 函数基础知识(二)

    目录 1 返回值 2 作用域 3 函数小高级 4 函数中高级 1 返回值 def func(arg): # .... return 9 # 返回值为9 默认:return None val = fun ...

  4. 第十章 ZYNQ-MIZ701 DDR3 PS读写操作方案

      本编文章的目的主要用简明的方法在纯PS里对DDR3进行读写. 本文所使用的开发板是Miz701 PC 开发环境版本:Vivado 2015.4 Xilinx SDK 2015.4 10.0本章难度 ...

  5. 【记忆化搜索】Happy Happy Prime Prime

    题目描述 RILEY VASHTEE: [reading from display] Find the next number in the sequence:313 331 367 ...? Wha ...

  6. Unity异步加载场景

    在游戏中,经常可以看到从一个关卡跳到另一个关卡时,有一个显眼的进度条,研究了下,其时也很简单: public void LoadAScene() {    StartCoroutine(LoadSce ...

  7. vue学习【一、开发环境搭建】

    一.安装node.js https://nodejs.org/en/ 建议安装LTS版本 安装完毕之后cmd命令查看node版本,如果不识别,记住设置环境变量 显示上面信息则安装成功 二.设置node ...

  8. css 对div用hover设置border,出现抖动和div走位问题,解决方法

    样式设置 : div:hover { border:1px solid red;} 当鼠标移动到div时,产生抖动和偏移. 产生的原因: 是因为设置border时设置了1px边框,多出的这1px,与其 ...

  9. splice与slice区别

    共同点:均是删除数组元素并返回结果. 区别:splice会改变原数组,而slice不会.并且splice会导致数组塌陷. 数组塌陷:使用splice删除元素时,剩余的数组元素索引的顺讯会改变. let ...

  10. TypeScript入门四:TypeScript的类(class)

    TypeScript类的基本使用(修饰符) TypeScript类的抽象类(abstract) TypeScript类的高级技巧 一.TypeScript类的基本使用(修饰符) TypeScript的 ...