HDU6198
Posted Penn000
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU6198相关的知识,希望对你有一定的参考价值。
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.
? 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)
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
1 //2017-09-10 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 #define LL long long 7 #define MAXN 100 8 9 using namespace std; 10 11 const int MOD = 998244353; 12 13 struct Matrix 14 { 15 LL a[MAXN][MAXN]; 16 int r, c; 17 }; 18 19 Matrix ori, res; 20 21 void init() 22 { 23 memset(res.a, 0, sizeof(res.a)); 24 res.r = 2; res.c = 2; 25 for(int i = 1; i <= 2; i++) 26 res.a[i][i] = 1; 27 ori.r = 2; ori.c = 2; 28 ori.a[1][1] = ori.a[1][2] = ori.a[2][1] = 1; 29 ori.a[2][2] = 0; 30 } 31 32 Matrix multi(Matrix x, Matrix y) 33 { 34 Matrix z; 35 memset(z.a, 0, sizeof(z.a)); 36 z.r = x.r, z.c = y.c; 37 for(int i = 1; i <= x.r; i++) 38 { 39 for(int k = 1; k <= x.c; k++) 40 { 41 if(x.a[i][k] == 0) continue; 42 for(int j = 1; j<= y.c; j++) 43 z.a[i][j] = (z.a[i][j] + (x.a[i][k] * y.a[k][j]) % MOD) % MOD; 44 } 45 } 46 return z; 47 } 48 void Matrix_mod(int n) 49 { 50 while(n) 51 { 52 if(n & 1) 53 res = multi(ori, res); 54 ori = multi(ori, ori); 55 n >>= 1; 56 } 57 printf("%lld\n", res.a[1][2]-1 % MOD); 58 } 59 60 int main() 61 { 62 int k; 63 while(scanf("%d", &k) != EOF) 64 { 65 init(); 66 k++; 67 Matrix_mod(2*k+1); 68 } 69 return 0; 70 }
以上是关于HDU6198的主要内容,如果未能解决你的问题,请参考以下文章
HDU 6198 number number number 矩阵快速幂 找规律
HDU6198 number number number(杜教BM模板)
HDU 6198(2017 ACM/ICPC Asia Regional Shenyang Online)
2017 ACM/ICPC Asia Regional Shenyang Online:number number number hdu 6198矩阵快速幂