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 & ...
随机推荐
- java代码(15) ---java8 Function 、Consumer 、Supplier
Java8 Function.Consumer.Supplier 有关JDK8新特性之前还有三篇博客: 1,java代码(1)---Java8 Lambda 2,java代码(2)---Java8 S ...
- MyBatis整合双数据源
有时候在项目中会遇到需要连接两个数据库的情况.本文就结合Spring和Mybatis来讲下怎么使用双数据源(或者是多数据源). 背景知识介绍 本文中实现多数据源的关键是Spring提供的Abstrac ...
- spring Cloud服务注册中心Eureka集群
spring Cloud服务注册中心Eureka集群配置: 在application.yml文件加以下配置: server: port: 8761 tomcat: uri-encoding: UTF- ...
- 使用请求头认证来测试需要授权的 API 接口
使用请求头认证来测试需要授权的 API 接口 Intro 有一些需要认证授权的接口在写测试用例的时候一般会先获取一个 token,然后再去调用接口,其实这样做的话很不灵活,一方面是存在着一定的安全性问 ...
- 00-02.kaliLinux-配置SSH服务
KaliLinux的SSH服务默认是需要手动配置好后才能使用,否则通过xShell等工具是无法连接上的. 修改SSH服务的配置文件 root@kali:~# cd /etc/ssh root@kali ...
- Java 切割字符串的几种方式
按效率排: 1.StringTokenizer切割 是java.util中的一个类,包含的api有: StringTokenizer的方法请参考上一篇. 其中,countTokens为length:n ...
- C# 9.0 新特性之模式匹配简化
阅读本文大概需要 2 分钟. 记得在 MS Build 2020 大会上,C# 语言开发项目经理 Mads Torgersen 宣称 C# 9.0 将会随着 .NET 5 在今年 11 月份正式发布. ...
- HTMLTestRunner生成html测试报告
使用:把文件放到项目某个文件夹中,引入方式如下 import unittest import env import vendor.report.HTMLTestRunnerNew as HTMLTes ...
- Redis在CentOS for LInux上安装详细教程
1.首先上传安装包,这里我以 redis-5.0.8.tar.gz 为例子. Linux下载redis地址:wget http://download.redis.io/releases/redis-5 ...
- .NET Framework、.NET Core 和 .NET 5+ 的产品生命周期
本文整理记录了 .NET Framework..NET Core 和 .NET 各个版本的产品支持周期和操作系统兼容性. 早于 .NET Framework 2.0 和 .NET Core 2.1 的 ...