5451 HDU Best Solver
链接: Best Solver
题目分析:
这个题目的关键点是需知道“共轭”.
如 :(A√B + C√D) 和 (A√B - C√D) 是共轭的
这个有一个规律 (A√B + C√D)^n + (A√B - C√D)^n 是一个整数(这里大家可以写写试试看)。
由题目可知:
因为我们要求的是:(5+2√6)^(1+2x), 我们可以构造一对共轭数。 (5-2√6),
因为0<(5-2√6) < 1, 所以 0<(5-2√6)^n < 1
故: 我们的式子由上述共轭的性质可知 y = (5+2√6)^(1+2x) + (5-2√6)^(1+2x) - 1;(y是要向下取整)
然后我们的y其实是有一个递推关系的:
F(n) = 10*F(n-1) - F(n-2).
证明如下:
设: Sn = (5+2√6)^n + (5-2√6)^n;
Sn * ( (5+2√6) + (5-2√6) ) = Sn * 10 = Sn+1 + Sn-1 * 1;
故: Sn+1 = 10*Sn - Sn-1;
=================================================================================================
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const LL INF = 0xfffffff;
const LL maxn = ;
int dp[maxn];
int GetLoop(int m)
{
memset(dp, , sizeof(dp));
dp[] = %m;
dp[] = %m;
for(int i=; i<=maxn-; i++)
{
dp[i] = (*dp[i-] - dp[i-]+m)%m; if(dp[i] == dp[] && dp[i-] == dp[])
return i-;
}
return -;
}
int QuickPow(int a,int b,int MOD)
{
int ans = , k = a; while(b)
{
if(b% == )
ans = (ans * k)%MOD;
k = (k * k)%MOD;
b /= ;
}
return (ans+)%MOD;
} int main()
{
int T, n, m, cas = ;
cin >> T;
while(T--)
{
cin >> n >> m; int LoopNode = GetLoop(m);
int ans = QuickPow(, n, LoopNode);
printf("Case #%d: %d\n",cas++, (dp[ans%LoopNode] - )%m);
}
return ;
}
5451 HDU Best Solver的更多相关文章
- Hdu 5451 Best Solver (2015 ACM/ICPC Asia Regional Shenyang Online) 暴力找循环节 + 递推
题目链接: Hdu 5451 Best Solver 题目描述: 对于,给出x和mod,求y向下取整后取余mod的值为多少? 解题思路: x的取值为[1, 232],看到这个指数,我的心情是异常崩 ...
- hdu 5451 Best Solver 矩阵循环群+矩阵快速幂
http://acm.hdu.edu.cn/showproblem.php?pid=5451 题意:给定x 求解 思路: 由斐波那契数列的两种表示方法, 之后可以转化为 线性表示 F[n] = ...
- 特征根法求通项+广义Fibonacci数列找循环节 - HDU 5451 Best Solver
Best Solver Problem's Link Mean: 给出x和M,求:(5+2√6)^(1+2x)的值.x<2^32,M<=46337. analyse: 这题需要用到高中的数 ...
- ACM学习历程—HDU 5451 Best Solver(Fibonacci数列 && 快速幂)(2015沈阳网赛1002题)
Problem Description The so-called best problem solver can easily solve this problem, with his/her ch ...
- HDU - 5451 Best Solver(循环节+矩阵快速幂)
Best Solver The so-called best problem solver can easily solve this problem, with his/her childhood ...
- HDU 5451 Best Solver 数论 快速幂 2015沈阳icpc
Best Solver Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/102400 K (Java/Others)Tota ...
- HDU 5451 Best Solver(fibonacci)
感谢这道题让我复习了一遍线代,还学习了一些奇奇怪怪的数论. 令 二项展开以后根号部分抵消了 显然有 所以要求的答案是 如果n比较小的话,可以直接对二项式快速幂,但是这题n很大 这个问题和矩阵的特征值以 ...
- HDU 5451 Best Solver
没有意识到循环节最大是M^2,用域Z_M下二阶可逆矩阵群的最大循环节(M^2-1)*(M^2-M)来做,考虑大数乘法,矩阵乘法,做到吐血.将代码贴在下方留作纪念. #include<bits/s ...
- HDOJ(HDU) 1898 Sempr == The Best Problem Solver?(水题、、、)
Problem Description As is known to all, Sempr(Liangjing Wang) had solved more than 1400 problems on ...
随机推荐
- Android(java)学习笔记204:自定义SmartImageView(继承自ImageView,扩展功能为自动获取网络路径图片)
1.有时候Android系统配置的UI控件,不能满足我们的需求,Android开发做到了一定程度,多少都会用到自定义控件,一方面是更加灵活,另一方面在大数据量的情况下自定义控件的效率比写布局文件更高. ...
- n进制转为十进制
主程序代码 - #include <stdio.h> #include <string.h> main() { long t1; int i, n, t, t3; ]; pri ...
- JAAS - Document
JAAS 参考文档: JAAS Reference Guide JAAS Authentication Tutorial JAAS Authorization Tutorial LoginModule ...
- HTML5 文件域+FileReader 分段读取文件并上传到服务器(六)
说明:使用Ajax方式上传,文件不能过大,最好小于三四百兆,因为过多的连续Ajax请求会使后台崩溃,获取InputStream中数据会为空,尤其在Google浏览器测试过程中. 1.简单分段读取文件为 ...
- Android开发手记(28) Handler和Looper
Android的消息处理有三个核心类:Looper,Handler和Message.其实还有一个Message Queue(消息队列),但是MQ被封装到Looper里面了,我们不会直接与MQ打交道.平 ...
- GridView中某一列值的总和(web)
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.R ...
- 查询两个日期(时间)以内的数据,between and 或 and 连>= <=,to_date()
between and 方法 select * from kk.kkhmd where larq between(to_date('2008-9-3','yyyy-mm-dd')) and (to_d ...
- TOM大师脚本-show space 多个版本,谢谢大牛们
示例一 该脚本需区分 对象的管理方式是 自动还是 手动, 对手动管理方式 的表显示很全面 SQL> exec show_space_old('MAN_TAB','DEV','TABLE'); F ...
- 分享最近写的 两条sql语句
1. 搭建基本环境 插入测试数据 insert into jgdm (jgdm,jgmc) values('12300000000','河南省');insert into jgdm (jgdm,jg ...
- [转]Delphi I/O Errors
The following are the Windows API (and former DOS) IO errors, which are also the IO errors often ret ...