2015北京现场赛 Hihocoder 1259 :A Math Problem
来源:互联网 发布:淘宝物流单号查询 编辑:程序博客网 时间:2024/05/16 09:29
K - A Math Problem
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluDescription
题意:已知f(1)=1,还有f(n)的一堆关系,定义g(t)为f(i)%k==t 的个数。求g(0)^g(1)....^g(k-1)。
思路;先化简公式可以得到,f(2n)=3f(n),f(2n+1)=3f(n)+1,很明显就要把一个数化成二进制,然后每一位的权值=3^(位数-1),然后就用数位dp统计就好了。代码如下:
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<cmath>#include<queue>#include<utility>#include<map>#define maxn 65540#define inf 0x3f3f3f3ftypedef long long LL;using namespace std;const int mod = 1e9 + 7;int num[70], k, vis[maxn];LL temp[maxn], dp[70][maxn], three[70];void dfs(int pos, int status, int limit){if (pos < 1){temp[status]++;return;}if (!limit&&vis[pos]){int now = status*three[pos + 1] % k;for (int i = 0; i < k; i++){temp[(now + i) % k] += dp[pos][i];}return;}int end = limit ? num[pos] : 1;for (int i = 0; i <= end; i++)dfs(pos - 1, (status * 3 + i) % k, limit&&i == end);if (!limit){vis[pos] = 1;for (int i = 0; i < k; i++){dp[pos][i] = temp[i]; }}}void solve(LL x){int len = 0;while (x){num[++len] = x & 1;x >>= 1;}dfs(len, 0, 1);}int main(){three[1] = 1;int t;scanf("%d", &t);while (t--){memset(temp, 0, sizeof(temp));memset(dp, -1, sizeof(dp));memset(vis, 0, sizeof(vis));LL n;scanf("%lld%d", &n, &k);for (int i = 2; i < 70; i++){three[i] = three[i - 1] * 3 % k;}solve(n);temp[0]--;LL ans = 0;for (int i = 0; i<k; i++){ans ^= temp[i];}printf("%lld\n", ans);}}
0 0
- 2015北京现场赛 Hihocoder 1259 :A Math Problem
- 2015 北京现场赛 A Math Problem
- Hihocoder 1259 :A Math Problem(2015 北京区域赛 K,二进制的数位dp)
- hihoCoder 1259 A Math Problem 数位dp
- hihoCoder 1259 A Math Problem 数位dp
- UVALive - 7271 A Math Problem (hihocoder 1259)
- 2015ACM-ICPC 北京赛区 Problem K. A Math Problem
- hihoCoder 1259 A Math Problem(数位dp)
- Hihocoder 1259 A Math Problem(数位DP+公式推导)
- 2015ICPC北京区域赛K. A Math Problem(数位DP)
- 2017 Wuhan University Programming Contest 现场赛I: A simple math problem(矩阵快速幂)
- 2017 Wuhan University Programming Contest 现场赛 I.A simple math problem(矩阵快速幂)
- hihocoder 1257 Snake Carpet 模拟构造题||2015北京现场赛I题
- hiho1251Today Is a Rainy Day【2015北京现场赛】BFS
- hihocoder 2015ACM-ICPC 北京赛区 Problem A. Xiongnu's Land
- hihoCoder 1227 & 2015 北京网络赛 A题
- 2015北京现场赛UVALive 7263 Today Is a Rainy Day 【bfs】
- 10.1训练赛---2014北京现场赛-A-hdu5112
- Java中的Runnable、Callable、Future、FutureTask的区别与示例
- 【vijos】【二分图最大匹配】银翼の舞
- 利用ffmpeg框架扩展android平台解码器
- webpack - 如何把es6编译成es5
- 课堂笔记
- 2015北京现场赛 Hihocoder 1259 :A Math Problem
- [BZOJ1500][NOI2005]维修数列(Splay)
- 安捷伦建议MDI指标
- 搜索指定视图上的TextField,从而取消其第一响应者
- SpringMVC的实现原理
- 求最长连续递增公共子序列
- 选择排序代码
- Ծ‸ Ծ 位运算
- CentOS7 配置阿里云yum源