HDU
来源:互联网 发布:下载itools软件 编辑:程序博客网 时间:2024/06/06 17:05
number number number
Problem Description
We define a sequence F :
⋅ F0=0,F1=1 ;
⋅ Fn=Fn−1+Fn−2 (n≥2) .
Give you an integerk , 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 integerk , you task is to find the minimal positive mjf−bad number.
The answer may be too large. Please print the answer modulo 998244353.
Give you an integer
Now, give you an integer
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 integerk which is described above. (1≤k≤109 )
Each test case includes an integer
Output
For each case, output the minimal mjf−bad number mod 998244353.
Sample Input
1
Sample Output
4
解题思路:矩阵快速幂求斐波那契数列,队友A了
#include<iostream>#include<deque>#include<memory.h>#include<stdio.h>#include<map>#include<string>#include<algorithm>#include<vector>#include<math.h>#include<stack>#include<queue>#include<set>using namespace std;const int mod=998244353;typedef long long int ll;typedef vector<long long> vec;typedef vector<vec> mat;ll n;mat mul(mat A,mat B){ mat C(A.size(),vec(B[0].size())); for(int i=0;i<A.size();i++) { for(int j=0;j<B.size();j++) { for(int k=0;k<B[0].size();k++) { C[i][j]+=(A[i][k]*B[k][j])%mod; C[i][j]%=mod; } } } return C;}mat pow(mat A,ll n){ mat B(A.size(),vec(A.size())); for(int i=0;i<A.size();i++) { B[i][i]=1; } while(n) { if(n&1) { B=mul(B,A); } A=mul(A,A); n>>=1; } return B;}void slove(ll n){ mat A(2,vec(2)); A[0][0]=1; A[0][1]=1; A[1][0]=1; A[1][1]=0; A=pow(A,n); printf("%lld\n",A[1][0]-1);}int main(){ while(scanf("%lld",&n)!=EOF) { slove(2*(n+1)+1); } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- Apache Spark2.0正式发布
- Java常用方法总结
- iOS学习笔记-137.RunLoop05——Runloop相关类3_CFRunLoopTimerRef(NSTimer)为何定时有时会失败
- 待补题
- 欢迎使用CSDN-markdown编辑器
- HDU
- Spark源码系列(一)spark-submit提交作业过程
- hdu 6205 card card card
- Typescript中的装饰器原理
- Spark源码系列(二)RDD详解
- PLSQL学习(三) 异常处理
- CentOS 7 时间同步
- mybatis #与$区别
- Spark源码系列(三)作业运行过程