为甚摸用了龟速乘还是50分
查看原帖
为甚摸用了龟速乘还是50分
422158
Realite楼主2022/2/20 18:48
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,p,k,a,c,m;
struct node{
	ll a[3][3];
	node(){
		memset(a,0,sizeof a);
	}
	void build(int x,int y){
		a[1][1]=x,a[1][2]=y;
	}
	void doit(int x){
		a[1][1]=x;
		a[2][1]=1;
		a[2][2]=1;
	}
};
node ans,g;
ll oh(ll x,ll y){
	ll an=0;
	for(;y;y>>=1){
		if(y&1)
		an=(an+x)%m;
		x=(x+x)%m;
	}
	return an;
}
node wow(const node &x,const node &y){
	node z;
	for(int i=1;i<=2;i++)
	for(int j=1;j<=2;j++)
	for(int k=1;k<=2;k++)
	z.a[i][j]=(oh(x.a[i][k],y.a[k][j])%m+z.a[i][j])%m;
	return z;
}
int main()
{
	cin>>m>>a>>c>>k>>n>>p;
	ans.build(k,c);
	g.doit(a);
	for(;n;n>>=1){
		if(n&1)
		ans=wow(ans,g);
		g=wow(g,g);
	}
	printf("%lld",ans.a[1][1]%p);
	return 0;
}

输入:8273648723648 7238468273648 72364876438 7283467823653 734864378 47747444

输出:-18859838

QAQ

2022/2/20 18:48
加载中...