summaryrefslogtreecommitdiff
path: root/content/math/linearRecurrence.cpp
diff options
context:
space:
mode:
authormzuenni <michi.zuendorf@gmail.com>2024-09-11 00:29:27 +0200
committermzuenni <michi.zuendorf@gmail.com>2024-09-11 00:29:27 +0200
commit0257f0b3c61f203f64c3817dfe19a08f6191517c (patch)
tree820d5c1ed1830bad5ee8f1498d9134ca4359393b /content/math/linearRecurrence.cpp
parentfacc5da35282ef30e5111cdc04942d118f4ae0c5 (diff)
moved stuff
Diffstat (limited to 'content/math/linearRecurrence.cpp')
-rw-r--r--content/math/linearRecurrence.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/content/math/linearRecurrence.cpp b/content/math/linearRecurrence.cpp
index c15c25c..ab86f71 100644
--- a/content/math/linearRecurrence.cpp
+++ b/content/math/linearRecurrence.cpp
@@ -10,21 +10,21 @@
// return c;
// }
-ll kthTerm(const vector<ll>& f, const vector<ll>& c, ll k){
+ll kthTerm(const vector<ll>& f, const vector<ll>& c, ll k) {
int n = sz(c);
- vector<ll> q(n+1, 1);
- for(int i = 1; i <= n; i++) q[i] = (mod-c[i-1])%mod;
+ vector<ll> q(n + 1, 1);
+ for (int i = 0; i < n; i++) q[i + 1] = (mod - c[i])%mod;
vector<ll> p = mul(f, q);
p.resize(n);
p.push_back(0);
- do{
+ do {
vector<ll> q2 = q;
- for(int i = 1; i <= n; i += 2) q2[i] = (mod - q2[i]) % mod;
+ for (int i = 1; i <= n; i += 2) q2[i] = (mod - q2[i]) % mod;
vector<ll> x = mul(p, q2), y = mul(q, q2);
- for(int i = 0; i <= n; i++){
+ for (int i = 0; i <= n; i++){
p[i] = i == n ? 0 : x[2*i + (k&1)];
q[i] = y[2*i];
}
- }while(k /= 2);
+ } while (k /= 2);
return p[0];
} \ No newline at end of file