HDU-5895 Mathematician QSC
来源:互联网 发布:淘宝抠图视频 编辑:程序博客网 时间:2024/05/07 16:41
题目大意:
已知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;}
0 0
- Hdu 5895 Mathematician QSC
- HDU-5895 Mathematician QSC
- HDU 5895 Mathematician QSC
- HDU 5895 Mathematician QSC
- HDU 5895 Mathematician QSC(欧拉定理推广)
- hdu 5895 Mathematician QSC(快速幂+指数循环节)
- HDU 5895&&2016 ACM/ICPC Asia Regional Shenyang Online1004 Mathematician QSC [矩阵加速+欧拉降幂]【数论】
- 2016 ACM/ICPC Asia Regional Shenyang Online HDU 5895 Mathematician QSC
- HDU 5895 Mathematician QSC(矩阵快速幂+扩展欧拉定理)
- 【HDU 5895】【指数循环节 矩阵 快速幂 逆元 推公式】Mathematician QSC 由递推式推公式
- 2016 ACM/ICPC Asia Regional Shenyang Online HDU 5895 Mathematician QSC(矩阵快速幂+高次幂取模)★ ★
- HDU 5895 Mathematician QSC (矩阵快速幂 + 逆元应用 + 指数循环节 + 欧拉函数)
- HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)——2016 ACM/ICPC Asia Regional Shenyang Online
- HDU 5895 Mathematician QSC(逆元应用+矩阵快速幂+数论知识)——2016 ACM/ICPC Asia Regional Shenyang Online
- HDU 5895 Mathematician QSC(矩阵乘法+循环节降幂+除法取模小技巧+快速幂)——2016 ACM/ICPC Asia Regional Shenyang Online
- hdoj 5895 Mathematician QSC 【数论----矩阵快速幂求解类斐波那契数列】
- 2016ACM-ICPC沈阳网络预选赛1004 Mathematician QSC
- hdu5895 Mathematician QSC(矩阵快速幂+逆元+降幂)
- SAX解析和PULL解析
- Effective C++总结
- Jquery即点即改简单小案例
- Android NDK 第一行代码
- BZOJ3622 已经没有什么好害怕的了
- HDU-5895 Mathematician QSC
- ios应用数据存储方式(偏好设置)
- Python3 基础学习
- 友之道
- 排序技术_各种算法原理 图解 代码实现
- (五)3 IO静态映射
- LintCode(0):准备篇:Java内存模型分析
- Android Studio预览出错的一些解决方案
- JSTL