P1349(违规紫杉
  • 板块题目总版
  • 楼主zhuoheng
  • 当前回复7
  • 已保存回复7
  • 发布时间2023/9/1 00:01
  • 上次更新2023/11/3 00:06:55
查看原帖
P1349(违规紫杉
1023698
zhuoheng楼主2023/9/1 00:01

求助,有没有不用矩阵快速幂的做法或调一下我的代码:

#include<cstdio>
#include<iostream>
using namespace std;
int a,b,ans;
int main()
{ 	
	int p,q,n,m;
	scanf("%d%d%d%d%d%d",&p,&q,&b,&a,&n,&m);
	if(n==1){
		cout<<b%m;
		return 0;
	}
	if(n==2){
		cout<<a%m;
		return 0;
	}
	p%=m;
	q%=m;
	a%=m;
	b%=m;
	for(int i=3;i<=n;i++){
		ans=(p*a+q*b)%m;
		b=a;
		a=ans;
	}
	printf("%d",ans);
	return 0;
}
2023/9/1 00:01
加载中...