Bitwise Equations
Where '|' denotes the bitwise OR operator.
For each case, there are two integers X and K (1 <= X, K <= 2000000000) in one line.
# include<iostream>
# include<cstdio>
# include<cmath>
# include<string>
# include<vector>
# include<list>
# include<set>
# include<map>
# include<queue>
# include<cstring>
# include<algorithm>
using namespace std; # define LL long long
# define REP(i,s,n) for(int i=s;i<n;++i)
# define CL(a,b) memset(a,b,sizeof(a))
# define CLL(a,b,n) fill(a,a+n,b) const double inf=1e30;
const int INF=1<<30;
const int N=1000; unsigned long long n,k; const unsigned long long a=0xffffffffffffffff;
unsigned long long ans; void dfs(unsigned x)
{
if(x<=0) return ;
int t=x;
int base=0;
while(t){
t/=2;
++base;
}
unsigned long long p=1;
int id;
for(int cnt=0,i=0;i<64&&cnt<=base;++i){
id=i;
if(n&(p<<i)){
++cnt;
if(cnt==base) ans|=(p<<i);
}
}
dfs(x-(p<<(base-1)));
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
cin>>n>>k;
n=~n;
ans=0;
dfs(k);
cout<<ans<<endl;
}
return 0;
}
Bitwise Equations的更多相关文章
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
Bitwise Equations Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 计算机学院大学生程序设计竞赛(2015’12) 1005 Bitwise Equations
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...
- CF 1064B Equations of Mathematical Magic(思维规律)
Description Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for. ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- [LeetCode] Bitwise AND of Numbers Range 数字范围位相与
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- JS魔法堂:再识Bitwise Operation & Bitwise Shift
Brief linkFly的<JavaScript-如果...没有方法>中提及如何手写Math.round方法,各种奇技淫招看着十分过瘾,最让我惊叹的是 ~~(x + )) ,完全通过加法 ...
- A.Kaw矩阵代数初步学习笔记 5. System of Equations
“矩阵代数初步”(Introduction to MATRIX ALGEBRA)课程由Prof. A.K.Kaw(University of South Florida)设计并讲授. PDF格式学习笔 ...
- 【leetcode】Bitwise AND of Numbers Range(middle)
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
随机推荐
- Python爬虫基础(四)Requests库的使用
requests文档 首先需要安装:pip install requests get请求 最基本的get: # -*- coding: utf-8 -*-import requests respons ...
- 数据库们~MySQL~MongoDB~Redis
mysql基础 mysql进阶 python操作mysql MongoDB Redis
- JSON数组成员反序列化
场景: 构想客户端能够传递如下格式JSON字符串到服务端: {"KeyValueSetList":[{"SN":"RQ1001"," ...
- nginx lua模块安装
1.安装LuaJIT,LuaJIT为LuaJIT is a Just-In-Time Compiler (JIT) for the Lua programming language wget http ...
- 解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'informat
解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'informat ...
- node-schedule 实现定时任务使用方法记录
在项目中有个每天0点执行的函数,本来想用setInterval来实现,但觉得这种需求以后应该还会有,自己写可能拓展性不高.搜了一下发现了node-schedule这个包.现在记录一下使用方法 node ...
- jq的$(function(){})与window.onload的区别
最近一直在研究jq的源码,书写jq的代码我们通常会包裹在一个$(function(){})函数中,jq的$(function(){})也就是$(document).ready(function(){} ...
- python2.7多线程的批量操作远程服务器
#!/usr/bin/env python #-*- coding:utf-8 -*- #多线程批量远程执行一条命令 # made in china import threading import s ...
- Java基础知识陷阱(十)
本文发表于本人博客. 上个星期由于时间比较紧所以未能继续写下去,今天再接再厉,专心 + 坚持这样离目标就越来越近了!废话少说说正题,今天我们还是来说说java中比较基础的知识,大家知道编写java程序 ...
- (转)JavaScriptSerializer,DataContractJsonSerializer解析JSON字符串功能小记
JsonAbout: using System;using System.Collections.Generic;using System.Linq;using System.Text;using S ...