[HihoCoder1259]A Math Problem
题目大意:
有一个函数f(n),满足3f(n)*f(2n+1)=f(2n)*(1+3f(n)),f(2n)<6f(n)。
我们用g(t)表示f(i)%k=t的i的个数,其中1<=i<=n。
问对于0<=x<k,所有的g(x)的异或和。
思路:
将函数用递推式表示为:
f(2n)=3f(n)
f(2n+1)=f(2n)+1
也就是说f(n)就是将n的二进制数串当作一个三进制数来算的值。
接下来就是一个简单的数位DP。
f[i][j]表示DP到第i位,前面那么多数所构成的三进制的值在模k意义下的值。
#include<cstdio>
#include<cctype>
#include<cstring>
typedef long long int64;
inline int64 getint() {
register char ch;
while(!isdigit(ch=getchar()));
register int64 x=ch^'';
while(isdigit(ch=getchar())) x=(((x<<)+x)<<)+(ch^'');
return x;
}
const int K=;
inline int log2(const float &x) {
return ((unsigned&)x>>&)-;
}
int64 f[][K];
inline int64 calc(const int64 &n,const int &k) {
int sum=;
const int len=log2(n);
memset(f[len&],,sizeof *f);
for(register int i=len;i>=;i--) {
memset(f[!(i&)],,sizeof *f);
const int cur=n>>i&;
sum=(sum*)%k;
for(register int j=;j<cur;j++) {
f[i&][(sum+j)%k]++;
}
sum=(sum+cur)%k;
for(register int j=;j<k;j++) {
f[!(i&)][j*%k]+=f[i&][j];
f[!(i&)][(j*+)%k]+=f[i&][j];
}
}
f[][]--;
f[][sum]++;
int64 ans=;
for(register int i=;i<k;i++) {
ans^=f[][i];
}
return ans;
}
int main() {
for(register int T=getint();T;T--) {
int64 n=getint();
int k=getint();
printf("%lld\n",calc(n,k));
}
return ;
}
[HihoCoder1259]A Math Problem的更多相关文章
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 5615 Jam's math problem
Jam's math problem Problem Description Jam has a math problem. He just learned factorization.He is t ...
- hdu----(5055)Bob and math problem(贪心)
Bob and math problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu------(1757)A Simple Math Problem(简单矩阵快速幂)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- BestCoder Round #70 Jam's math problem(hdu 5615)
Problem Description Jam has a math problem. He just learned factorization. He is trying to factorize ...
- FZYZ-2071 A Simple Math Problem IX
P2071 -- A Simple Math Problem IX 时间限制:1000MS 内存限制:262144KB 状态:Accepted 标签: 数学问题-博弈论 ...
- Jam's math problem(思维)
Jam's math problem Submit Status Practice HDU 5615 Description Jam has a math problem. He just lea ...
- HDU 5055 Bob and math problem(结构体)
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...
随机推荐
- 关于RecylerView:1.在ScrollView的RecylerView滑动事件的处理。2.item之间的距离 小数取整
1.在ScrollView的RecylerView滑动事件的处理. 在布局文件中在RecylerView外包裹一层相对布局 2.RecylerView item之间的距离 (1)编写SpaceItem ...
- 通过or注入py脚本
代码思路 1.主要还是参考了别人的代码,确实自己写的和别人写的出路很大,主要归咎还是自己代码能力待提高吧. 2.将功能集合成一个函数,然后通过*args这个小技巧去调用.函数的参数不是argv的值,但 ...
- CreateProcess中的部分参数理解
函数原型,这里写Unicode版本 WINBASEAPIBOOLWINAPICreateProcessW( _In_opt_ LPCWSTR lpApplicationName, //可执行文件名字 ...
- python自动开发之第二十二天
知识点概要 - Session - CSRF - Model操作 - Form验证(ModelForm) - 中间件 - 缓存 - 信号 一. Session 基于Cookie做用户验证时:敏感信息不 ...
- Vue组件-组件的事件
自定义事件 通过prop属性,父组件可以向子组件传递数据,而子组件的自定义事件就是用来将内部的数据报告给父组件的. <div id="app3"> <my-com ...
- java===java基础学习(16)---final
final-----概念 1.当不希望父类的某个方法被子类覆盖(override)时,可以用final关键字修饰. 2.当不希望类的某个变量的值被修改时,可以用final修饰.如果要用final,则必 ...
- c json实战引擎四 , 最后❤跳跃
引言 - 以前那些系列 长活短说, 写的最终 scjson 纯c跨平台引擎, 希望在合适场景中替代老的csjon引擎, 速度更快, 更轻巧. 下面也是算一个系列吧. 从cjson 中得到灵感, 外加 ...
- xtraTabControl学习
winform 首先是动态添加page面,并且在page页面上添加一个form窗体 DevExpress.XtraTab.XtraTabPage page = new DevExpress.XtraT ...
- C# 笔记——覆盖和重写
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- FTP webReq.ContentType异常的处理
FtpWebRequest webReq; webReq = (FtpWebRequest)FtpWebRequest.Create(new Uri(updateFileUrl)); FtpWebRe ...