题目大意

给出一个整数\(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. Conscription(POJ 3723)

    原题如下: Conscription Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16584   Accepted: 57 ...

  2. 乔悟空-CTF-i春秋-Web-Upload

    2020.09.03 ai 做过的题,两天不看就忘了-- 做题 题目 题目地址 thinking-- 打开网站 告诉了文件在flag.php中,所以写个php,把flag.php文件读取出来就行 盗来 ...

  3. Oracle闪回flashback

    参考资料:Using Oracle Flashback Technology Oracle 11g的新特性闪回操作 闪回查询 闪回查询 闪回版本查询 闪回事务查询 闪回数据 闪回表 闪回删除 闪回数据 ...

  4. [算法]美团春招笔试题C-求有趣子序列数(DP)

    题目 输入n,以及长度为n的数组元素 输出数组的非空子序列中有多少个"有趣序列"mod 998244353,有趣序列指所有元素满足arr[i]%i == 0, i从0记. 例: 输 ...

  5. 【译】Visual Studio 2019 的 Local Process with Kubernetes

    今天,我们自豪地宣布 Local Process with Kubernetes 的预览版已加入到 Visual Studio 2019 16.7 Preview 2 中.  Local Proces ...

  6. spring中配事务的工具配置

    <!--配置事务--><bean id="transactionManager" class="org.springframework.jdbc.dat ...

  7. 使用spring mvc拦截器 会话失效处理

    import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import ...

  8. 刷题[安恒DASCTF2020四月春季赛]Ez unserialize

    解题思路 打开直接源码,没别的,审就完事了 代码审计 <?php show_source("index.php"); function write($data) { retu ...

  9. brew清华镜像

    https://mirror.tuna.tsinghua.edu.cn/help/homebrew/

  10. Hive中的数据类型以及案例实操

    @ 目录 基本数据类型 集合数据类型 案例实操 基本数据类型 对于Hive的String类型相当于数据库的varchar类型,该类型是一个可变的字符串,不过它不能声明其中最多能存储多少个字符,理论上它 ...