题意:已知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. Linux centosVMware LNMP架构介绍、MySQL安装、PHP安装、Nginx介绍

    一. LNMP架构介绍 和LAMP不同的是,提供web服务的是Nginx 并且php是作为一个独立服务存在的,这个服务叫做php-fpm Nginx直接处理静态请求,动态请求会转发给php-fpm   ...

  2. 109、Java中String类之截取部分子字符串

    01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...

  3. Write-up-CH4INRULZ_v1.0.1

    关于 下载地址:点我 哔哩哔哩:哔哩哔哩 信息收集 网卡:vboxnet0,192.168.56.1/24,Nmap扫存活主机发现IP为192.168.56.101 ➜ ~ nmap -sn 192. ...

  4. 记录:一次使用私有LoadBalance provider,工具metallb的故障排除

    使用metallb工具,目的是为私有环境下,不借助GRE或Azure等云商的LB, 通过metallb-system工具IP池给k8s service提供external-ip.但是,由于设置meta ...

  5. Java编程打开运行exe程序

    String path = "notepad.exe"; //(C:\Program Files\Tencent\QQ\Bin\qq.exe) try { Runtime runt ...

  6. exec函数的执行对用户ID的影响

    exec不会创建新进程,只是分析加载程序文件或者shell执行文件,替换父进程的代码段.数据段.栈段,一个进程可以执行多个exec来执行多个程序,但进程只有一个 父进程经常是waitpid,获取子进程 ...

  7. jQuery Validation Engine

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...

  8. android EditText中inputType的属性列表

    android 1.5以后添加了软件虚拟键盘的功能,所以在输入提示中将会有对应的软键盘模式 android中inputType属性在EditText输入值时启动的虚拟键盘的风格有着重要的作用.这也大大 ...

  9. IdentityServer4专题之二:OpenID介绍

    1.基于概念 OpenId是一个以用户为中心的数字身份识别框架,它具有开放.分散.自由等特性.OpenId的创建是基于这样一个概念:我们可以通过URI(或者URL网址)来识别一个网站.同样,我们也可以 ...

  10. NLP之gensim

    一. 利用 jieba 进行分词,关键词提取 利用gensim下面的corpora,models,similarities 进行语料库建立,模型tfidf算法,稀疏矩阵相似度分析 # -*- codi ...