number number number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 118    Accepted Submission(s): 79

Problem Description

We define a sequence F:

⋅ F0=0,F1=1;
⋅ Fn=Fn−1+Fn−2 (n≥2).

Give you an integer k, if a positive number n can be expressed by
n=Fa1+Fa2+...+Fak where 0≤a1≤a2≤⋯≤ak, this positive number is mjf−good. Otherwise, this positive number is mjf−bad.
Now, give you an integer k, you task is to find the minimal positive mjf−bad number.
The answer may be too large. Please print the answer modulo 998244353.

 

Input

There are about 500 test cases, end up with EOF.
Each test case includes an integer k which is described above. (1≤k≤109)
 

Output

For each case, output the minimal mjf−bad number mod 998244353.
 

Sample Input

1
 

Sample Output

4
 

Source

 
ans = F(2*n+1)-1
 
 //2017-09-10
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define MAXN 100 using namespace std; const int MOD = ; struct Matrix
{
LL a[MAXN][MAXN];
int r, c;
}; Matrix ori, res; void init()
{
memset(res.a, , sizeof(res.a));
res.r = ; res.c = ;
for(int i = ; i <= ; i++)
res.a[i][i] = ;
ori.r = ; ori.c = ;
ori.a[][] = ori.a[][] = ori.a[][] = ;
ori.a[][] = ;
} Matrix multi(Matrix x, Matrix y)
{
Matrix z;
memset(z.a, , sizeof(z.a));
z.r = x.r, z.c = y.c;
for(int i = ; i <= x.r; i++)
{
for(int k = ; k <= x.c; k++)
{
if(x.a[i][k] == ) continue;
for(int j = ; j<= y.c; j++)
z.a[i][j] = (z.a[i][j] + (x.a[i][k] * y.a[k][j]) % MOD) % MOD;
}
}
return z;
}
void Matrix_mod(int n)
{
while(n)
{
if(n & )
res = multi(ori, res);
ori = multi(ori, ori);
n >>= ;
}
printf("%lld\n", res.a[][]- % MOD);
} int main()
{
int k;
while(scanf("%d", &k) != EOF)
{
init();
k++;
Matrix_mod(*k+);
}
return ;
}

HDU6198的更多相关文章

  1. [HDU6198]number number number

    题目大意: 给定一个数k表示你可以从包括0的斐波那契数列中任取k个数,得到它们的和.求最小的不能得到的自然数. 思路: 打表找规律,可以发现答案为f(2k+3)-1,然后用公式f(i)=f(i/2)* ...

  2. hdu6198 number number number(递推公式黑科技)

    number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

随机推荐

  1. Select count(*)、Count(1)、Count(0)的区别和执行效率比较

    记得很早以前就有人跟我说过,在使用count的时候要用count(1)而不要用count(*),因为使用count(*)的时候会对所有的列进行扫描,相比而言count(1)不用扫描所有列,所以coun ...

  2. 多个JDK下TOMCAT运行设置

    当OS中含有多个JDK版本时,设置TOMCAT下JAVA环境变量信息的办法: 1.在setclasspath.bat或者setclasspath.sh下设置 set JAVA_HOME=d:\java ...

  3. 【重要通知】本人所有技术文章转移至https://zzqcn.github.io

    本人所有技术文章转移至 https://zzqcn.github.io

  4. Twisted 框架 初印象

    上面是twisted官网推荐的书籍,从封面可以看到,是一堆大蟒(python)纠缠在一起,这里可以说明twisted是一个基于pyhton语言,支持各种网络协议(包括UDP,TCP,TLS和其他应用层 ...

  5. vue教程1-06 v-bind属性、class和style

    vue教程1-06 属性.class和style 一.属性 属性: v-bind:src="" width/height/title.... 简写: :src="&quo ...

  6. ThreadLocal是否会引发内存泄露的分析 good

    这篇文章,主要解决一下疑惑: 1. ThreadLocal.ThreadLocalMap中提到的弱引用,弱引用究竟会不会被回收? 2. 弱引用什么情况下回收? 3. JAVA的ThreadLocal和 ...

  7. CLR关于语言文化的类型一CultureInfo类和字符串与线程的关联

    .Net Frameword使用System.Globalization.Culture类型表示一个"语言/国家"对(根据RFC 1766标准).例如,'en-US'代表美国英语, ...

  8. win2003 远程连接限制

    1.单击开始->运行,输入gpedit.msc,打开组策略编辑器,找到计算机配置 ->管理模版 -> Windows组件 ->终端服务.把限制连接数量的属性修改成我们需要的数字 ...

  9. Centos7 开启端口

    CentOS7默认没有使用iptables,所以通过编辑iptables的配置文件来开启80端口是不可以的. CentOS 7 采用了 firewalld 防火墙. 如要查询是否开启80端口: [ro ...

  10. 微信小程序——<radio></radio>大小改变

    css样式改变大小: transform:scale(.7);