题意:已知F= 0,F= 1,Fn = Fn - 1 + Fn - 2(n >= 2), 且若n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤a,n为正数,则n为mjf-good,否则为mjf-bad,给定k,求最小的mjf-bad。

分析:找规律可得,F2*k+3 - 1,矩阵快速幂即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const LL MOD = 998244353;
const double pi = acos(-1.0);
const int MAXN = 100000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
struct Matrix{
LL r, c;
LL matrix[2][2];
Matrix(LL rr, LL cc):r(rr), c(cc){
memset(matrix, 0, sizeof matrix);
}
};
Matrix mul(Matrix a, Matrix b){
Matrix ans(a.r, b.c);
for(int i = 0; i < a.r; ++i){
for(int j = 0; j < b.c; ++j){
for(int k = 0; k < a.c; ++k){
(ans.matrix[i][j] += (a.matrix[i][k] * b.matrix[k][j]) % MOD) %= MOD;
}
}
}
return ans;
}
int Q_POW(Matrix a, int n){
Matrix ans(a.r, a.c);
ans.matrix[0][0] = ans.matrix[1][1] = 1;
while(n){
if(n & 1) ans = mul(ans, a);
a = mul(a, a);
n >>= 1;
}
return ans.matrix[0][0] % MOD;
}
int main(){
int k;
while(scanf("%d", &k) == 1){
int n = 5 + (k - 1) * 2;
Matrix a(2, 2);
a.matrix[0][0] = a.matrix[0][1] = a.matrix[1][0] = 1;
printf("%lld\n", (Q_POW(a, n - 1) - 1 + MOD) % MOD);
}
return 0;
}

  

HDU - 6198 number number number(规律+矩阵快速幂)的更多相关文章

  1. HDU 1005 Number Sequence【斐波那契数列/循环节找规律/矩阵快速幂/求(A * f(n - 1) + B * f(n - 2)) mod 7】

    Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. (hdu 6030) Happy Necklace 找规律+矩阵快速幂

    题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6030 Problem Description Little Q wants to buy a nec ...

  3. 2017ACM暑期多校联合训练 - Team 2 1006 HDU 6050 Funny Function (找规律 矩阵快速幂)

    题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e ...

  4. HDU 3292 【佩尔方程求解 && 矩阵快速幂】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...

  5. HDU 5171 GTY's birthday gift 矩阵快速幂

    GTY's birthday gift Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  6. HDU - 2604 Queuing(递推式+矩阵快速幂)

    Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  7. HDU 2256 Problem of Precision (矩阵快速幂)(推算)

    Problem of Precision Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  8. HDU 2855 斐波那契+矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=2855 化简这个公式,多写出几组就会发现规律 d[n]=F[2*n] 后面的任务就是矩阵快速幂拍一个斐波那契模板出 ...

  9. HDU 5950:Recursive sequence(矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:给出 a,b,n,递推出 f(n) = f(n-1) + f(n-2) * 2 + n ^ 4. f ...

随机推荐

  1. 5(计算机网络)从物理层到MAC层

    故事就从我的大学宿舍开始讲起吧.作为一个八零后,我要暴露年龄了. 我们宿舍四个人,大一的时候学校不让上网,不给开通网络.但是,宿舍有一个人比较有钱,率先买了一台电脑.那买了电脑干什么呢? 首先,有单机 ...

  2. Linux进程管理(一)

    目录 Linux进程管理(一) 参考 pstree命令 pidof命令 pmap命令 pwdx命令 ps命令 nice调优 发送信号 Linux进程管理(一)

  3. JS中,跨域调用(本地)另一个项目的方法

    IP地址,因为是本地的项目,所以我一开始写的是127.0.0.1...,但不对.应该写本机的IP地址才对!

  4. redis 初识与安装

    一.redis介绍 redis是一个key-value存储系统.和Memcached类似,它支持存储的values类型相对更多,包括字符串.列表.哈希散列表.集合,有序集合. 这些数据类型都支持pus ...

  5. nginx_2_nginx进程模型

    1.nginx进程模型概述 在上一节我们已经已经成功在linux服务器上安装了nginx,启动nginx后,查看进程:ps -ef | grep nginx 能看到启动nginx进程后,有一个mast ...

  6. 十九 Spring的JDBC模版使用: 模版的CRUD的操作

    Spring的JDBC模版使用: 模版的CRUD的操作 保存操作 修改操作 删除操作 查询操作 import com.ithheima.jdbc.domian.Account; @RunWith(Sp ...

  7. Linux中用systemctl命令管理服务

    systemctl start foo.service 启动服务systemctl restart foo.service 重启服务systemctl stop foo.service 停止服务sys ...

  8. MariaDB——相关概念与sql语句

    数据库变量   数据库的两个目录 数据存放目录:/var/lib/mysql/     配置文件目录:/etc/my.cnf.d/ 查看数据库的变量 show global variables lik ...

  9. JDBC--获取数据库连接

    1.JDBC(Java Database Connectivity)是一个独立于特定数据库管理系统.统一的sQL数据库存取和操作的公共接口. 2.Java中的几种数据库存取技术: --1)JDBC直接 ...

  10. 「SP1043」GSS1 - Can you answer these queries I

    传送门 Luogu 解题思路 这题就是 GSS3 的一个退化版,不带修改操作的区间最大子段和,没什么好讲的. 细节注意事项 咕咕咕 参考代码 #include <algorithm> #i ...