题意:已知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;
}

  

最新文章

  1. volatile关键字详解
  2. [地图SkyLine二次开发]框架(2)
  3. 【转】浅析Sql Server参数化查询
  4. wamp 中如何管理两个dedeCms站点
  5. andriod CheckBox
  6. 烂泥:KVM使用裸设备配置虚拟机
  7. STM
  8. DB层面上的设计 分库分表 读写分离 集群化 负载均衡
  9. 关闭linux下的使用的端口
  10. 机器学习第三课(EM算法和高斯混合模型)
  11. super 和this的用法
  12. UML 行为图之用例图 总结
  13. NDK开发之调用方法
  14. 1/8=1/a+1/b,a,b为自然数
  15. 《VIM-Adventures攻略》 LEVEL 1-3
  16. Js 时间间隔计算(间隔天数)
  17. OpenGL框架+QT版
  18. ADFS 2.0 配置简介 PartⅡ – 配置 ADFS 信任关系
  19. 学习Android路上的一些感慨和总结,慢慢来,比较快!
  20. java面向对象中四种权限(private,protected,public,友好型)详解

热门文章

  1. scala的trait执行报错: 错误: 找不到或无法加载主类 cn.itcast.scala.`trait`
  2. 【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP&lt;string,int&gt;映射)
  3. 【PAT甲级】1008 Elevator (20 分)
  4. 通过命令行提交更新代码到gitlab上
  5. JavaScript图形实例:正弦曲线
  6. html弹出框播放视频
  7. 第1节 kafka消息队列:11、kafka的数据不丢失机制,以及kafka-manager监控工具的使用;12、课程总结
  8. JDBC--PreparedStatement使用
  9. 导弹拦截p1020(LIS问题)
  10. 076、Java数组之定义数组