__int128 矩阵乘法 10pts 求助
查看原帖
__int128 矩阵乘法 10pts 求助
220824
yyz1005楼主2023/5/19 13:27
#include<bits/stdc++.h>
using namespace std;
typedef __int128 ll;
ll p,a,c,xf,n;
ll G;
ll read(){
	ll x = 0;
	char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	x = ch-'0';
	ch = getchar();
	while(isdigit(ch)){
		x = x*10+ch-'0';
		ch = getchar();
	}
	return x;
}
void print(ll x){
	if(x>9) print(x/10);
	putchar(x%10+'0');
}
struct matrix{
	ll l,h;
	ll q[5][5];
	//2*2;
	void clean(){
		memset(q,0,sizeof(q));
	}
	void full(ll x){
		memset(q,x,sizeof(q));
	}
	matrix operator *(const matrix &b) const{
		matrix res;
		res.clean();
		for(ll i = 1; i <= h; i++){
			for(ll j = 1; j <= b.l; j++){
				for(ll k = 1; k <= l; k++){
					res.q[i][j] += q[i][k]*q[k][j];
					res.q[i][j]%=p;
				}
			}
		}
		return res;
	}
};
matrix mul(matrix base,ll k){
	matrix res;
	res.l = res.h = 2;
	res.clean();
	if(k==1) return base;
	res = mul(base,k>>1);
	res = res*res;
	if(k&1) res = res*base;
	return res;
}
int main(){
	p = read();a = read();c = read();
	xf = read();n = read();G = read(); 
	matrix base;
	base.l = base.h = 2;
	base.clean();
	base.q[1][1] = a;
	base.q[2][1] = c;
	base.q[1][2] = 1;
	base.q[2][2] = 0;
	base = mul(base,n);
	matrix p2p;
	p2p.l = 2;
	p2p.h = 1;
	p2p.q[1][1] = xf;
	p2p.q[1][2] = 1;
	base = base*p2p;
	ll xn = base.q[1][1];
	print(xn%G);
	return 0;
}
2023/5/19 13:27
加载中...