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. IDEA下tomcat启动后 server乱码,Tomcat Catalina Log乱码问题的解决

    如果你初接触Idea,一定会遇到控制台乱码的问题,这里和eclipse有点不一样,看如下办法: 乱码的根本原因:Windows系统的cmd是GBK编码的,所以IDEA的下方log输出的部分的编码也是G ...

  2. 南昌网络赛J. Distance on the tree 树链剖分

    Distance on the tree 题目链接 https://nanti.jisuanke.com/t/38229 Describe DSM(Data Structure Master) onc ...

  3. # OpenGL常用函数详解(持续更新)

    OpenGL常用函数详解(持续更新) 初始化 void glutInit(int* argc,char** argv)初始化GULT库,对应main函数的两个参数 void gultInitWindo ...

  4. 三分钟搞定Python中的装饰器

    python的装饰器是python的特色高级功能之一,言简意赅得说,其作用是在不改变其原有函数和类的定义的基础上,给他们增添新的功能. 装饰器存在的意义是什么呢?我们知道,在python中函数可以调用 ...

  5. Windows安全日志

    在运行中输入:eventvwr.msc,即可打开事件日志. 登录类型 描述 2 互动(键盘和屏幕的登录系统) 3 网络(即连接到共享文件夹从其他地方在这台电脑上网络) 4 批处理(即计划任务) 5 服 ...

  6. Python学习3——列表和元组

    一.通用序列操作——索引.切片.相加.相乘.成员资格检查 1.索引,正序从0开始为第一个元素,逆序从-1开始,-1为最后一个元素 >>> greeting[0] 'h' >&g ...

  7. Wannafly挑战赛23

    B. 游戏 大意: $n$堆石子, 第$i$堆初始$a_i$, 每次只能选一堆, 假设一堆个数$x$, 只能取$x$的约数, 求先手第一步必胜取法. SG入门题, 预处理出所有$SG$值. 先手要必胜 ...

  8. Python集合的常用方法

    注释很详细 collection={,,"apple","orange","cat"} # 查看一个数是否在集合中 in print(&qu ...

  9. ORCALE字符集AL32UTF8和ZHS16GBK的互相转换

    AL32UTF8转成ZHS16GBK cmd中输入“SQLPLUS”,回车,然后再在用户名下输入“SYS AS SYSDBA”,回车 密码后面输入“SYS”,回车.这里输入密码是隐式的,所以看不见,只 ...

  10. Redis缓存策略设计及常见问题

    Redis缓存设计及常见问题 缓存能够有效地加速应用的读写速度,同时也可以降低后端负载,对日常应用的开发至关重要.下面会介绍缓存使用技巧和设计方案,包含如下内容:缓存的收益和成本分析.缓存更新策略的选 ...