题目大意:

已知f[0] = 0, f[1] = 1, f[i] = f[i-1] * 2 + f[i-2],且g[n] = g[n-1] + f[n] * f[n],现在给出n,y,x,s,问你x^(g[n*y]) mod (s + 1)的值为多少。

解题思路:

首先可以得到的是g[n] = f[n] * f[n+1] / 2

证明方式就是xjb打表加上猜加上数学归纳法,别问我怎么猜到的我是用了这个网站http://oeis.org/

因此g[n]可以很轻松的得到了。那么现在的问题就是a^b mod p的值应该怎么求

这里提供一份关于求解这个值的非常详细的博客:传送门

代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;typedef long long LL;
typedef pair<LL, LL> pi;LL euler(LL n) {LL ans = n;for (LL i = 2; i * i <= n; ++i) {if (n % i == 0) {ans -= ans / i;while (n % i == 0)n /= i;}}if (n > 1) ans -= ans / n;return ans;
}
LL fastMul(LL a, LL b, LL mod) {LL ans = 1;while (b) {if (b & 1) ans = (ans * a) % mod;b >>= 1;a = (a * a) % mod;}return ans;
}
pi fastMatrix(LL n, LL mod) {LL t11, t12, t21, t22;LL bas[4] = {2, 1, 1, 0};LL ans[4] = {1, 0, 0, 1};while (n) {if (n & 1) {t11 = ((ans[0] * bas[0]) % mod + (ans[1] * bas[2]) % mod) % mod;t12 = ((ans[0] * bas[1]) % mod + (ans[1] * bas[3]) % mod) % mod;t21 = ((ans[2] * bas[0]) % mod + (ans[3] * bas[2]) % mod) % mod;t22 = ((ans[2] * bas[1]) % mod + (ans[3] * bas[3]) % mod) % mod;ans[0] = t11; ans[1] = t12; ans[2] = t21; ans[3] = t22;}n >>= 1;t11 = ((bas[0] * bas[0]) % mod + (bas[1] * bas[2]) % mod) % mod;t12 = ((bas[0] * bas[1]) % mod + (bas[1] * bas[3]) % mod) % mod;t21 = ((bas[2] * bas[0]) % mod + (bas[3] * bas[2]) % mod) % mod;t22 = ((bas[2] * bas[1]) % mod + (bas[3] * bas[3]) % mod) % mod;bas[0] = t11; bas[1] = t12; bas[2] = t21; bas[3] = t22;}return make_pair(ans[0], ans[2]);
}
LL solve(LL n, LL y, LL x, LL s) {LL eul = euler(s + 1);pi tmp = fastMatrix(n * y, eul * 2);LL N = ((tmp.first * tmp.second) % (eul * 2)) / 2 + eul;return fastMul(x, N, s + 1);
}
int main() {LL n, y, x, s, t;scanf("%lld", &t);while (t--) {scanf("%lld%lld%lld%lld", &n, &y, &x, &s);printf("%lld\n", solve(n, y, x, s));}return 0;
}

转载于:https://www.cnblogs.com/wiklvrain/p/8179351.html

HDU-5895 Mathematician QSC相关推荐

  1. HDU 5895 Mathematician QSC

    题目地址 欧拉函数+矩阵快速幂 1 #include<cstdio> 2 #include<algorithm> 3 #include<string.h> 4 #i ...

  2. 【HDU - 5900】QSC and Master(区间dp)

    题干: Every school has some legends, Northeastern University is the same. Enter from the north gate of ...

  3. c语言定义int 输出4386,C语言 · 矩阵乘法

    问题描述 输入两个矩阵,分别是m*s,s*n大小.输出两个矩阵相乘的结果. 输入格式 第一行,空格隔开的三个正整数m,s,n(均不超过200). 接下来m行,每行s个空格隔开的整数,表示矩阵A(i,j ...

  4. 2016.9.18 --- Shenyang ol

    1001 Resident Evil 1002 List wants to travel 1003 hannnnah_j's Biological Test 1004 Mathematician QS ...

  5. HDU5900 QSC and Master(区间DP + 最小费用最大流)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, ...

  6. HDU 4389 - X mod f(x)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4389 2012多校,第9场,1010 . 问题是,询问区间内 存在多少个 哈沙德数(Harshad ...

  7. hdu 4389 囧,打表

    http://acm.hdu.edu.cn/showproblem.php?pid=4389 题意 :一个数能被他各个位数之和整除则符合要求,给L,R,问区间里有多少个数符合要求. 囧,居然打表就能过 ...

  8. HDU——1106排序(istringstream的使用、STLvector练习)

    排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  9. hdu 5438 Ponds 拓扑排序

    Ponds Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/contests/contest_showproblem ...

最新文章

  1. 二叉树线索化示意图_103-线索化二叉树思路图解
  2. Windows下Git Bash的基本使用
  3. php xml 动态添加数据,php向xml中添加数据一例
  4. C语言-定义与初始化总结
  5. 玩转Mixly – 5、Arduino AVR编程 之 逻辑
  6. 7 pe系统安装_【软件课程之家】PE系统安装教程
  7. 全志和瑞芯微比较_哪家强_全志瑞芯微海思PK 智能芯片哪家强?
  8. UE3 Lightmass 工具
  9. SpringBoot文件上传大小设置(yml中配置)
  10. Ubuntu-显卡驱动-nvidia-smi报错:couldn‘t communicate with the NVIDIA driver
  11. rds对mysql优化_RDS MySQL优化方案
  12. android toast 显示在最上面,Android Toast在屏幕上移动
  13. 微信任意用户密码修改漏洞分析
  14. ubuntu 下安装 face_recognition
  15. 3d旋转图片立方体特效
  16. 钢铁侠java_现代版“钢铁侠”,无所不能的程序员,java工程师实现人造器官!...
  17. 2020北京公积金查看与提取
  18. 调用浏览器下载图片 java实现
  19. C语言笔记 · 输入函数(scanf(),getchar(),getche(),getch(),gets())
  20. 在H5移动端开发强制竖屏,横屏时提示

热门文章

  1. c++ 线程什么时候run_阿里后端Java面试题:启动线程是start()还是run()?为什么?...
  2. excel python插件_利用 Python 插件 xlwings 读写 Excel
  3. 抖音云控_抖音云控/快手云控:引领5G电商短视频新潮流
  4. 4路组相连cache设计_浅谈 Cache
  5. php本地怎么接受小程序图片,怎么把本地图片当作小程序背景
  6. php java 单点登录_php实现多站点共用session实现单点登录的方法详解
  7. 【竞赛算法学习】学术前沿趋势分析-论文数据统计
  8. 根据id删除localstorage数据_原生js利用localstorage实现简易TODO list应用
  9. maven deploy上传本地jar至私服
  10. QT编程中遇到的问题总结