题目大意

给出一个整数\(n\),已知\(0\le u,v\le n\),求满足\(a\ xor\ b=u\)且\(a+b=v\)的\(a、b\)对数

样例1输入

3

样例1输出

5

/*

u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)

u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.)

u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.)

u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.)

u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.)

*/

样例2输入

1422

样例2输出

52277

样例3输入

1000000000000000000

样例3输出

787014179

思路

用暴力打表,前20个答案分别为1、2、4、5、8、10、13、14、18、21、26、28、33、36、40、41、46、50、57、60、68。

可以发现规律

\(\begin{cases}
a_{2k}=2a_{k-1}+a_k \\
a_{2k-1}=2a_k+a_{k-1} \\
\end{cases}\)

代码

#include <cstdio>
#include <map>
typedef long long ll;
const int Mod=1e9+7;
const int maxn=1000000+5;
using namespace std;
ll a[30]={1,2,4,5,8,10,13,14,18,21,26,28,33,36,40,41,46,50,57,60,68};
map<ll,ll> mp;//记忆化 ll dfs(ll x) {
if(x<=20)
return a[x];
if(mp[x])
return mp[x];
if(x%2)
return mp[x]=(2*dfs(x/2)%Mod+dfs(x/2-1)%Mod)%Mod;
else
return mp[x]=(2*dfs(x/2-1)%Mod+dfs(x/2)%Mod)%Mod;
} int main() {
ll n;
scanf("%lld",&n);
printf("%lld\n",dfs(n));
return 0;
}

【找规律】ARC 066D Xor Sum AtCoder - 2272的更多相关文章

  1. ARC 066D Xor Sum AtCoder - 2272 (打表找规律)

    Problem Statement You are given a positive integer N. Find the number of the pairs of integers u and ...

  2. GCD XOR UVA 12716 找规律 给定一个n,找多少对(a,b)满足1<=b<=a<=n,gcd(a,b)=a^b;

    /** 题目:GCD XOR UVA 12716 链接:https://vjudge.net/problem/UVA-12716 题意:给定一个n,找多少对(a,b)满足1<=b<=a&l ...

  3. 牛客小白月赛5 G 异或(xor) 【找规律】

    题目链接: https://www.nowcoder.com/acm/contest/135/g 题目描述 从前,Apojacsleam家的水族箱里,养了一群热带鱼. 在这几条热带鱼里,Apojacs ...

  4. AtCoder Beginner Contest 098 D - Xor Sum 2

    D - Xor Sum 2 Time limit : 2sec / Memory limit : 1024MB Score : 500 points Problem Statement There i ...

  5. # E. Mahmoud and Ehab and the xor-MST dp/数学+找规律+xor

    E. Mahmoud and Ehab and the xor-MST dp/数学/找规律 题意 给出一个完全图的阶数n(1e18),点由0---n-1编号,边的权则为编号间的异或,问最小生成树是多少 ...

  6. 找规律/数位DP HDOJ 4722 Good Numbers

    题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...

  7. HDU 4825 Xor Sum(经典01字典树+贪心)

    Xor Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others) Total ...

  8. The Cow Lineup_找规律

    Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled ...

  9. LightOJ 13361336 - Sigma Function (找规律 + 唯一分解定理)

    http://lightoj.com/volume_showproblem.php?problem=1336 Sigma Function Time Limit:2000MS     Memory L ...

随机推荐

  1. Linux:apache目录结构和配置文件详解

    bin目录下的常见命令 conf目录 htdocs目录 logs目录 httpd.conf文件解析. 如果后期自己新创建了新的站点目录,就要重新增加对应的目录权限配置 extra/目录下配置文件解析 ...

  2. Mybatis如何执行Select语句,你真的知道吗?

    持续原创输出,点击上方蓝字关注我吧 作者:不才陈某 博客:https://chenjiabing666.github.io 前言 本篇文章是Myabtis源码分析的第三篇,前两篇分别介绍了Mybati ...

  3. Linux里隐藏的计算器,你知道它的奥秘吗?

    Linux里隐藏的计算器,你知道它的奥秘吗? 大家都知道,windows下有个计算器工具,我们在工作生活中经常使用到它.但是,你可知Linux下也同样有个计算器吗? 当然,良许说的是命令行下的计算器工 ...

  4. jekins使用的坑

    1.日志打满 一个周末回来,服务器的磁盘就写满了 现象如下,最后是修改catalina脚本 添加了如下配置 ###jekins log problem#########export JAVA_OPTS ...

  5. netty字符串流分包

    @Override protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Obj ...

  6. c语言之结构

    定义结构: struct point { int x; int y; }; 定义结构并声明变量: struct point { int x; int y; }pt1,pt2,pt3; 声明结构变量 s ...

  7. python实现多分类评价指标

    1.什么是多分类? 参考:https://www.jianshu.com/p/9332fcfbd197 针对多类问题的分类中,具体讲有两种,即multiclass classification和mul ...

  8. shellcode生成框架

    因为vs编译后自己会生成很多东西,我们稍微配置下 先获取kernel32基址 __declspec(naked) DWORD getKernel32() { __asm { mov eax, fs:[ ...

  9. 八皇后问题(n-皇后问题)

    JAVA 作为一道经典的题目,那必然要用经典的dfs来做 dfs:深度优先搜索----纵向搜索符合条件的内容,走到底时回到上一个路口再走到底再回去,套娃至结束. 条件:在一个n*n的国际棋盘上摆放n个 ...

  10. jquery学习:

    1.什么是jQuery jquery 全称 javaScript Query.是js的一个框架.本质上仍然是js. 2.jQuery的特点 支持各种主流的浏览器. 使用特别简单 拥有便捷的插件扩展机制 ...