H3PO5 @ 2025-01-10 17:18:49
马蜂不是很好,记录
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll num[12][12];
ll ans[12][12];
ll tmp[12][12];
ll fin[12];
ll n, m, p, q, r, t, u, v, w, x, y, z;
ll qmul(ll a, ll b){
ll res = 0;
ll flag = 1;
if(b < 0){
flag = -1;
b = -b;
}
while (b != 0){
if (b & 1) res = (res + a) % m;
a = (a << 1) % m;
b >>= 1;
}
return res * flag;
}
void qpow(ll tme){
for (int i = 1; i <= 11; i++){
for (int j = 1; j <= 11; j++)
ans[i][j] = 0;
ans[i][i] = 1;
}
while (tme != 0){
if (tme & 1){
for (int i = 1; i <= 11; i++)
for (int j = 1; j <= 11; j++){
tmp[i][j] = 0;
for (int k = 1; k <= 11; k++)
tmp[i][j] = (tmp[i][j] + qmul(ans[i][k], num[k][j]) % m) % m;
}
for (int i = 1; i <= 11; i++)
for (int j = 1; j <= 11; j++)
ans[i][j] = tmp[i][j];
}
for (int i = 1; i <= 11; i++)
for (int j = 1; j <= 11; j++){
tmp[i][j] = 0;
for (int k = 1; k <= 11; k++)
tmp[i][j] = (tmp[i][j] + qmul(num[i][k], num[k][j]) % m) % m;
}
for (int i = 1; i <= 11; i++)
for (int j = 1; j <= 11; j++)
num[i][j] = tmp[i][j];
tme >>= 1;
}
return;
}
int main(){
cin >> n >> m >> p >> q >> r >> t >> u >> v >> w >> x >> y >> z;
if (n == 1){
printf("nodgd 1\nCiocio 1\nNicole 1");
return 0;
}
if (n == 2){
printf("nodgd 3\nCiocio 3\nNicole 3");
return 0;
}
num[1][1] = p; num[1][2] = q; num[1][3] = 1; num[1][5] = 1; num[1][7] = r; num[1][8] = t; num[1][11] = 1;
num[2][1] = 1;
num[3][1] = 1; num[3][3] = u; num[3][4] = v; num[3][5] = 1; num[3][9] = 1;
num[4][3] = 1;
num[5][1] = 1; num[5][3] = 1; num[5][5] = x; num[5][6] = y; num[5][8] = 1; num[5][10] = 1; num[5][11] = z;
num[6][5] = 1;
num[7][7] = 1; num[7][8] = 2; num[7][11] = 1;
num[8][8] = 1; num[8][11] = 1;
num[9][9] = w;
num[10][10] = z;
num[11][11] = 1;
fin[1] = fin[3] = fin[5] = 3;
fin[2] = fin[4] = fin[6] = fin[7] = fin[8] = fin[11] = 1;
fin[9] = w;
fin[10] = z;
qpow(n - 3);
ll ans1 = 0, ans2 = 0, ans3 = 0;
for (int i = 1; i <= 11; i++){
ans1 = (ans1 + fin[i] * num[1][i] % m) % m;
ans2 = (ans2 + fin[i] * num[3][i] % m) % m;
ans3 = (ans3 + fin[i] * num[5][i] % m) % m;
}
printf("nodgd %lld\nCiocio %lld\nNicole %lld", ans1, ans2, ans3);
return 0;
}