比赛 2022级数学专题练习赛9 评测结果 AAAAAAAAAAAAAAAEEEEE
题目名称 兔农 最终得分 75
用户昵称 op_组撒头屯 运行时间 1.140 s
代码语言 C++ 内存使用 4.29 MiB
提交时间 2023-02-08 21:12:18
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define si set<int>
#define unsi unordered_set<int>
#define qi queue<int>
#define sti stack<int>
#define pqi priority_queue<int>
#define mii map<int,int>
#define unmii unordered_map<int,int>
#define fi first
#define se second
#define pb push_back
#define clr(f,n) memset(f,0,sizeof(int)*(n))
#define cpy(f,g,n) memcpy(f,g,sizeof(int)*(n))
const int N=1000000+5;
ll f[N];
bool ok[N];
int main(){
	freopen ("noi2011_rabbit.in","r",stdin);
	freopen ("noi2011_rabbit.out","w",stdout);
	ll n,k,p;scanf("%lld%lld%lld",&n,&k,&p);
	f[1]=f[2]=1;
	for (int i=3;i<=n;i++){
	    f[i]=(f[i-1]+f[i-2])%k;
	    if (f[i]==1){
	        ok[i]=1;f[i]=0;
        }
    }
    for (int i=3;i<=n;i++){
        f[i]=(f[i-1]+f[i-2])%p;
        if (ok[i])f[i]=(f[i]+p-1)%p;
    }
    printf("%lld\n",f[n]);
    return 0;
}