// compile: g++ -o data data.cpp -std=gnu++20 -DLOCAL -g
// run: ./data < data.in
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#ifdef LOCAL
#endif
#define sz(v) ((int)(v).size())
#define PV(v) for (int i=0;i<v.size();++i)cout<<v[i]<<" ";cout<<endl;
#define int long long
#define MAXN 110
#define MAXM 40
using namespace std;
int n, K, P;
int unlucky = 0;
int add_(int a, int b, int p) {return (a + b) % p; }
int minus_(int a, int b, int p) {return (a - b + p) % p; }
int power(int a, int b, int p) {
if (b == 1) return a % p;
int mid = power(a, b>>1, p);
if (b & 1) return ((mid * mid) * a) % p;
else return (mid * mid) % p;
}
// vector<int> mul(int a[][MAXM], vector<int> &x) {
// vector<int> y(K, 0);
// for (int i = 0; i < K; ++i) {
// for (int j = 0; j < K; ++j) {
// y[i] += a[i][j] * x[j];
// }
// }
// return y;
// }
vector<vector<int>> mul(vector<vector<int>> a, vector<vector<int>> b) {
int n = a.size(), m = b.size(), p = b[0].size();
vector<vector<int>> f(n, vector<int>(p, 0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < p; ++j) {
for (int k = 0; k < m; ++k) {
f[i][j] = (f[i][j] + ((a[i][k] * b[k][j]) % P)) % P;
}
}
}
return f;
}
vector<vector<int>> mat_pow(vector<vector<int>> a, int n) {
if (n == 1) return a;
vector<vector<int>> mid = mat_pow(a, n >> 1);
if (n & 1) return mul(mul(mid, mid), a);
else return mul(mid, mid);
}
void print_vec(vector<vector<int>> A) {
for (int i = 0; i < K; ++i) {
for (int j = 0; j < K; ++j) {
cout << A[i][j] << " ";
}
cout << endl;
}
cout << endl;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> K >> P;
for (int s = 0; s < K; ++s) {
cout << s << endl;
vector<vector<int>> A(K, vector<int>(K, 1));
for (int i = 0; i < K; ++i) {
for (int j = 0; j < K; ++j) {
if ((2 * (i-j+K)) % K == s) A[i][j] = 0;
}
}
print_vec(A);
A = mul(A, A);
print_vec(A);
A = mul(A, A);
print_vec(A);
A = mul(A, A);
print_vec(A);
break;
vector<vector<int>> x(K, vector<int>(1, 0));
x[0][0] = 1;
A = mat_pow(A, n);
x = mul(A, x);
unlucky = add_(unlucky, x[s][0], P);
}
int lucky = minus_(power(K, n, P), unlucky, P);
cout << lucky << endl;
return 0;
}
Alright, listen up! If you’re looking for a fresh place to play, I’d suggest hitting up 99ok5. Smooth interface and always keep finding new games on the platform. Here’s the link to check them out: 99ok5
Sodo.pro? Nghe tên cũng pro phết nhỉ. Có ai giàu lên nhờ chơi ở đây không? Confess! Access here: sodo.pro
Okay, so I recently checked out Crickexloginbet, and honestly? It’s not bad! The whole login process was smooth, and I appreciated how straightforward it was. Plus, the betting options are pretty decent. Worth a look if you’re into that kinda thing. Check it out here: crickexloginbet
Logging in is a breeze and the game selection is top notch. I love how intuitive the layout is for new players. jilibbcomlogin
This platform has a very unique feel and the rewards are actually generous. I am really enjoying my time on vnf16878vipp.
I love how easy it is to navigate the site. It makes the whole experience much more enjoyable. Check out phkilig22login.
Really impressed with the customer support here. They solved my deposit issue in minutes. I highly recommend phfairyph for their reliability.