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 & ...
随机推荐
- python3 优惠券查询GUI程序
from tkinter import ttkfrom tkinter import messageboximport pymssqlimport tkinterimport decimalimpor ...
- 括号匹配-算法详细题解LeetCode
题目:有效的括号 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. ...
- Spring Boot 教程 - Elasticsearch
1. Elasticsearch简介 Elasticsearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elasticsearc ...
- ubuntu安装ssh服务器
1.安装 sudo apt-get install openssh-server 2.配置文件路径 / etc/ssh/sshd_config 3.操作 sudo /etc/init.d/ssh st ...
- .Net Core微服务入门全纪录(一)——项目搭建
前言 写这篇博客主要目的是记录一下自己的学习过程,只能是简单入门级别的,因为水平有限就写到哪算哪吧,写的不对之处欢迎指正. 什么是微服务? 关于微服务的概念解释网上有很多... 个人理解,微服务是一种 ...
- CSS布局之Flex布局
Flex布局,可以简便.完整.响应式地实现各种页面布局. 浏览器支持:得到所有浏览器的支持.(注:Flex布局将成为未来布局的首选方案) 一. Flex布局的概念 Flex是Flexible Bo ...
- TensorFlow笔记——关于MNIST数据的一个简单的例子
这个程序参考自极客学院. from tensorflow.examples.tutorials.mnist import input_data import tensorflow as tf # MN ...
- @bzoj - 5104@ Fib数列
目录 @description@ @solution@ @accepted code@ @details@ @description@ Fib数列为1,1,2,3,5,8... 求在Mod10^9+9 ...
- 第m大的身份证号码(局部排序代全局、结构体排序)
第m大的身份证号码(点击) 时间限制: 1 Sec 内存限制: 128 MB ...
- IDEA Gradle项目控制台输出乱码
idea 更新到2019.2.3没有这个选项. 可以点击 help->edit custom vm options 然后加上 -Dfile.encoding=utf-8 重启一下就好了