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 & ...
随机推荐
- 给Linux小白的CentOS8.1基本安装说明
写在前面的话:用过Linux的同学应该都会觉得Linux安装是件非常简单的事情,根本不值得用博客记下来!但是我发现,其实没接触过Linux的同学还真不一定会装,就像在IT行业工作过几年但一直用Wind ...
- Java中的堆和栈
Java中的堆和栈 栈内存 存放基本数据类型和引用变量 堆内存 存放运行时创建的对象 一般来说,通过new关键字创建出来的对象都放在堆内存中 由于JVM是基于堆栈的虚拟机,而每个Java程序都运行在一 ...
- Python--函数&过程
函数式编程与过程式编程打的区分:过程是没有返回值的函数,过程在python3中也有返回值,为None 函数的作用:代码复用.保持代码的一致性.使代码更容易扩展 过程的定义与调用: 1 def func ...
- Python 3中,import win32com.client 出错
在 import win32com.client 时,出现了界面: Traceback (most recent call last): File "<pyshell#1>&qu ...
- 如何在react中使用decorator
2020-03-27 如何在react中使用decorator decorator目前都需要修改babel才能使用 说一下具体的操作方法 踩了一天的坑... 步骤1: yarn create reac ...
- mysql where与 having的区别
where是针对磁盘的数据文件,having是针对存在内存的结果集的筛选. 例如: select name ,(xxx - xxx) as a from table where a > 10; ...
- curlPost和curlGet 请求链接
//getcurl get读取数据function curlGet($url){ $UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) App ...
- Java 内存溢出(java.lang.OutOfMemoryError)的常见情况和处理方式
导致OutOfMemoryError异常的常见原因有以下几种: 内存中加载的数据量过于庞大,如一次从数据库取出过多数据: 集合类中有对对象的引用,使用完后未清空,使得JVM不能回收: 代码中存在死循环 ...
- YII2.0安装教程,数据库配置前后台
1.首先下载yii-advanced-app-2.0.6.tgz 我本地服务用的是Apache 2.解压到E:\wamp\www\yii2目录下面将目录advanced下所有文件剪切到 E:\wamp ...
- MAC App破解之路十 Particle Design
这个软件破解非常简单: 修改: [PaddleStatic Yz6nrtNwF4].直接返回1 效果: