[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 ...
随机推荐
- parseInt函数
1.概念 解析字符串,返回一个整数 2.说明 接收两个参数:需要转化的字符串.需要解析的数字基数,介于2~36之间(若该值神略或为0,数字将以10为基数解析:若参数大于36或小于2则返回NaN) pa ...
- Mojo_1_第一个简单例子
use Mojolicious::Lite; #根目录,Get方法打开 #正接显示文本text get '/' => sub{ my $service = shift; $service-> ...
- Msfvenom学习总结-MSF反弹webshell
1. –p (- -payload-options) 添加载荷payload. 载荷这个东西比较多,这个软件就是根据对应的载荷payload生成对应平台下的后门,所以只有选对payload,再填 ...
- linux percpu机制解析【转】
转自:http://blog.csdn.net/wh8_2011/article/details/53138377 一.概述 每cpu变量是最简单也是最重要的同步技术.每cpu变量主要是数据结构数组, ...
- linux下终端游戏
sl 一列火车 oneko 一只淘气的小猫
- 阿波罗11号登月飞船电脑控制系统源码(AGC)
阿波罗11号登月飞船电脑控制系统源码(AGC) http://download.csdn.net/detail/downiis6/9574926 down url: https://github.co ...
- C#反射动态调用dll中的方法及使用QuartZ.net实现作业调度
using Quartz; using Quartz.Impl; using System; using System.Collections.Generic; using System.Linq; ...
- STL不同容器的使用方法
以下内容摘自:http://blog.csdn.net/u014465639/article/details/70241850 1.vector(需要导入头文件#include <vector& ...
- Socket与URL通信比较
转至链接:http://blog.csdn.net/qq_15848173/article/details/46328399 利用URL通信和Socket进行通信有很多相似之处.他们都是利用建立连接. ...
- shell常见操作整理(更新)
查看文件第20到30行的内容 法一:[root@oldboy ~]# seq 100 > ett.txt [root@oldboy ~]# head -30 ett.txt | tail -11 ...