Xor_Sum 题解
题目
You are given a positive integer \(N(1≦N≦10^{18})\). Find the number of the pairs of integers \(u\) and \(v (0≦u,v≦N)\) such that there exist two non-negative integers \(a\) and \(b\) satisfying \(a xor b=u\) and \(a+b=v\). Here, \(xor\) denotes the bitwise exclusive OR. Since it can be extremely large, compute the answer modulo \(10^9+7\).
给出正整数\(N\),求出整数对\(u\)和\(v (0≤u,v≤N)\)的数目,使得存在两个非负整数\(a\)和\(b\)满足\(a xor b = u\) 和\(a + b= v\)。这里,\(xor\)表示按位异或。对答案取模\(10^9 + 7\)
输入格式
The input is given from Standard Input in the following format: \(N\)
一个整数\(N\)
输出格式
Print the number of the possible pairs of integers \(u\) and \(v\) ,modulo \(10^9+7\).
\(u,v\)对的数量模\(10^9+7\)
输入样例
3
输出样例
5
题解
把\(n=1,2,3,4,5...\)的答案手算出来, 是1, 2, 4, 5, 8, 10, 13, 14, 18, 21, 26, 28, 33, 36, 40, 41, 46, 50, 57, 60...
然后找规律, 如果不好找, 可以在这个网站搜索.
用记忆化搜索优化效率, 如果开数组开不下, 用map即可
我怀疑这个不是正解
代码
#include <cstdio>
#include <map>
const long long MOD = 1e9 + 7;
std::map<long long, long long> dp;
long long f(long long x) {
if (dp[x]) return dp[x] % MOD;
return dp[x] = (f((x - 1) / 2) + f(x / 2) + f((x - 2) / 2)) % MOD;
}
int main() {
long long n;
scanf("%lld", &n);
dp[0] = 1;
dp[1] = 2;
printf("%lld\n", f(n) % MOD);
}
Xor_Sum 题解的更多相关文章
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
- 网络流n题 题解
学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...
- CF100965C题解..
求方程 \[ \begin{array}\\ \sum_{i=1}^n x_i & \equiv & a_1 \pmod{p} \\ \sum_{i=1}^n x_i^2 & ...
随机推荐
- 02 . Zabbix配置监控项及聚合图形
安装Zabbix Agent监控本机 安装agent软件 与server端不同,Agent只需安装zabbix-agent包 cat /etc/yum.repos.d/zabbix.repo [zab ...
- 2.使用nexus3配置docker私有仓库
1,配置走起 1,创建blob存储 登陆之后,先创建一个用于存储镜像的空间. 定义一个name,下边的内容会自动补全. 然后保存. 注意:实际生产中使用,建议服务器存储500G或以上. 2,创建一个h ...
- Jquery封装: WebSocket插件
1 $(function() { var websocket = null; //浏览器是否支持websocket if ("WebSocket" in window) { try ...
- @bzoj - 3148@ 没头脑和不高兴
目录 @description@ @solution@ @part 1:期望@ @part 2:方差@ @accepted code@ @details@ @description@ 没头脑和不高兴是 ...
- 面试:在面试中关于List(ArrayList、LinkedList)集合会怎么问呢?你该如何回答呢?
前言 在一开始基础面的时候,很多面试官可能会问List集合一些基础知识,比如: ArrayList默认大小是多少,是如何扩容的? ArrayList和LinkedList的底层数据结构是什么? Arr ...
- cb34a_c++_STL_算法_查找算法_(7)_lower_bound
cb34a_c++_STL_算法_查找算法_(7)_lower_bound//针对已序区间的查找算法,如set,multiset关联容器-自动排序lower_bound()--第一个可能的位置uppe ...
- MongoDB文档(二)--查询
(一)查询文档 查询文档可以使用以下方法 # 以非结构化的方式显示所有的文档 db.<collectionName>.find(document) # 以结构化的方式显示所有文档 db.& ...
- 国外的教授都说,用这个方式21天就能学会python,这是中国速度
你尝试过吗?按照这个方式,用21天就能学会python编程. 在今年的疫情期间,在家的时间何止21天,有这样一位做财务的朋友,为了提高自己的数据分析能力,在家通过这个方式,跟着21天的规划,坚 ...
- 解决github打不开问题
2020.06.22 使用以下方式: 在https://github.com.ipaddress.com/找到: 在https://fastly.net.ipaddress.com/github.gl ...
- 【解读】Http协议
一.HTTP简介 1.HTTP协议,即超文本传输协议(Hypertext transfer protocol).是一种详细规定了浏览器和万维网(WWW = World Wide Web)服务器之间互相 ...