number number number
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 390 Accepted Submission(s): 247
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
题目大意:
给出一个公式,输入一个n,输出一个n个斐波那契数列相加不能得到的最小数字。
解题思路:
找规律,列出前几个数字,可以发现,输出的是斐波那契数列中第n*2+3个数字减去1,由于数据范围给的很大,因此不能用平常方法计算数列中的数,用矩阵快速幂计算。本人当时比赛没写出来,之后又学的这个。
代码:
#include<stdio.h> #include<string.h> #define inf 998244353 typedef struct stu{ long long a[2][2]; }st; st fun(st a,st b) { st c; memset(c.a,0,sizeof(a.a)); for(int i=0;i<2;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) { c.a[i][j]+=a.a[i][k]*b.a[k][j]; c.a[i][j]%=inf; } return c; } void fun1(long long n) { st c,d; c.a[0][0]=c.a[0][1]=c.a[1][0]=1; c.a[1][1]=0; memset(d.a,0,sizeof(d.a)); for(int i=0;i<2;i++) d.a[i][i]=1; while(n) { if(n&1) d=fun(d,c); c=fun(c,c); n/=2; } printf("%lld\n",d.a[0][1]-1); } int main() { long long n; while(scanf("%lld",&n)!=EOF) { fun1(n*2+3); } return 0;}
会了这个方法,找到了规律,这题还是很简单的。