当前位置:网站首页>[training Day8] series [matrix multiplication]
[training Day8] series [matrix multiplication]
2022-07-24 20:10:00 【VL——MOESR】

Ideas :
We consider constructing a transition matrix
f[1] The exponent of is multiplied by b[k],f[2] The exponent of is multiplied by b[k-1]+ The original , And so on
So we can construct
0 0 0 0 …… 0 b[k]
1 0 0 0 …… 0 b[k-1]
0 1 0 0 …… 0 b[k-2]
……
0 0 0 0…… 1 b[1]
c o d e code code
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cctype>
#define mo 998244352
#define ll long long
using namespace std;
ll mod = 998244353;
ll n, k;
ll f[210], c[210][210];
struct matrix
{
ll a[210][210];
matrix() {
memset(a, 0, sizeof(a)); }
}A;
matrix ans;
matrix operator *(const matrix &x,const matrix &y)
{
matrix z;
for(register int i = 0; i < k; i ++)
for(register int j = 0; j < k; j ++)
for(register int t = 0; t < k; t ++)
z.a[i][j] = (z.a[i][j] + x.a[i][t] * y.a[t][j] % mo) % mo;
return z;
}
inline matrix qpow(ll x) {
ans = A;
for(; x; A = A * A, x >>= 1)
if(x & 1) ans = ans * A;
return ans;
}
ll qpow2(ll x, ll k) {
ll ans = 1;
while(k) {
if(k & 1) ans= ans * x % mod;
x = x * x % mod;
k >>= 1;
}
return ans;
}
int main() {
freopen("seq.in", "r", stdin);
freopen("seq.out", "w", stdout);
scanf("%lld%lld", &n, &k);
for(ll i = k - 1; i >= 0; i --)
scanf("%lld", &A.a[i][k - 1]);
for(ll i = 1; i < k; i ++) A.a[i][i - 1] = 1;
for(ll i = 0; i < k; i ++) scanf("%lld", &f[i]);
if(n <= k) {
printf("%lld", f[n - 1]);
return 0;
}
n -= k;
ans = qpow(n - 1);
ll sum = 1;
for(ll i = 0; i < k; i ++)
sum = sum * qpow2(f[i], ans.a[i][k - 1]) % mod;
printf("%lld", sum);
return 0;
}
边栏推荐
- Maya coffee machine modeling
- clip:learning transferable visual models from natural language supervision
- 【德味】安全:如何为行人提供更多保护
- Sword finger offer 40. minimum number of K
- Interface component devaxpress asp Net v22.1 - new office 365 dark theme
- Istio一之Envoy工作原理
- Introduction to WDK development 1- basic environment construction and the first driver (VS2010)
- Wechat applet -that.setdata ({}) set complex field data
- Talk about your transformation test development process
- Ask a question: is there an error msg = ora-04036: instance usage when using CDC to monitor oracle
猜你喜欢

(posted) differences and connections between beanfactory and factorybean

Introduction to WDK development 1- basic environment construction and the first driver (VS2010)

Safe way -- Analysis of single pipe reverse connection back door

Pix2seq: Google brain proposes a unified interface for CV tasks!
![2019 Hangdian multi school first 6581 vacation [thinking]](/img/38/5a74d3ef346d6801f9da8fd3a4b23a.png)
2019 Hangdian multi school first 6581 vacation [thinking]

The ark compiler is coming. What about APK reinforcement

Todolist case

Modbus communication protocol specification (Chinese) sharing

Alibaba cloud technology expert Yang Zeqiang: building observable capabilities on elastic computing cloud

The U.S. economy continues to be weak, and Microsoft has frozen recruitment: the cloud business and security software departments have become the hardest hit
随机推荐
(posted) differences and connections between beanfactory and factorybean
Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
02 | 环境准备:如何在windows下安装和配置一个基本的php开发环境?
Sql164 next day retention rate of new users per day in November 2021
Data transmission of different fragments in the same activity
Sword finger offer 48. the longest substring without repeated characters
871. Sum of divisors
TCP sliding window, singleton mode (lazy and hungry) double checked locking / double checked locking (DCL)
Use of paging assistant PageHelper
Connect the smart WiFi remote control in the home assistant
Review the code implementation of memcpy function
01 | 开篇词:手把手教你搭建一个博客网站
Pix2seq: Google brain proposes a unified interface for CV tasks!
Cmake series tutorial 1- initial cmake
Hcip early summary
Sword finger offer 52. The first common node of the two linked lists
Detailed explanation of ELF format (I)
Istio一之Envoy工作原理
Alibaba cloud technology expert Yang Zeqiang: building observable capabilities on elastic computing cloud
"Hualiu is the top stream"? Share your idea of yyds