灵异事件?(关于 Mod)
  • 板块灌水区
  • 楼主zhouzihang1
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/7/22 19:11
  • 上次更新2024/7/22 20:12:41
查看原帖
灵异事件?(关于 Mod)
827018
zhouzihang1楼主2024/7/22 19:11

这是 ABC293E 我的 AC 代码:

想问一下为什么码中标注的取模加了就AC,去掉就Wa呢?

#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll x,n,Mod;
struct matrix{
	ll a[5][5];
	matrix(){memset(a,0,sizeof(a));}
};
matrix operator*(const matrix &x,const matrix &y)
{
	matrix res;
	for(int i=1;i<=2;i++)
		for(int j=1;j<=2;j++)
			for(int k=1;k<=2;k++)
				(res.a[i][j]+=1LL*x.a[i][k]*y.a[k][j]%Mod)%=Mod;
	return res;
}
void qpow(ll b)
{
	matrix A,res;
	res.a[1][1]=res.a[1][2]=1;
	A.a[1][1]=x;A.a[2][1]=A.a[2][2]=1;
	while(b)
	{
		if(b&1) res=res*A;
		A=A*A;b>>=1;
	}
	printf("%lld\n",res.a[1][1]%Mod/*这里*/);
}
int main()
{
	scanf("%lld%lld%lld",&x,&n,&Mod);
	qpow(n-1);
	return 0;
}
2024/7/22 19:11
加载中...