思路:

f= can * f1xn * f2yn * f3zn, 首先dp计算指数部分a= an-1 + an-2 + an-3 + 2 * n - 6, 而an-1 = an-2 + an-3 + an-4 + 2 * n - 8,相减可以得到a= 2 * an-1 - an-4 + 2。xn,yn和zn是普通的三阶斐波那契。计算完指数部分要对p - 1取模(由费马小定理知p为质数的情况ap - 1 % p = 1),然后再用快速幂计算各个部分相乘即可。

再记录一种两个互相交互的递推式的矩阵快速幂构造:

                    

实现:

 #include <bits/stdc++.h>
using namespace std; typedef long long ll;
typedef vector<vector<ll>> matrix; const ll mod = 1e9 + , p_mod = mod - ; matrix mat_mul(matrix & a, matrix & b)
{
matrix c(a.size(), vector<ll>(b[].size()));
for (int i = ; i < a.size(); i++)
{
for (int k = ; k < a[].size(); k++)
{
for (int j = ; j < b[].size(); j++)
{
c[i][j] = ((c[i][j] + a[i][k] * b[k][j] % p_mod) + p_mod) % p_mod;
}
}
}
return c;
} matrix mat_pow(matrix & a, ll n)
{
matrix res(a.size(), vector<ll>(a[].size()));
for (int i = ; i < a.size(); i++) res[i][i] = ;
while (n > )
{
if (n & ) res = mat_mul(res, a);
a = mat_mul(a, a);
n >>= ;
}
return res;
} ll pow(ll x, ll n)
{
ll res = ;
while (n > )
{
if (n & ) res = res * x % mod;
x = x * x % mod;
n >>= ;
}
return res;
} int main()
{
ll n, f1, f2, f3, c;
while (cin >> n >> f1 >> f2 >> f3 >> c)
{
matrix x(, vector<ll>(, )), a(, vector<ll>(, ));
x[][] = ; x[][] = -; x[][] = ;
x[][] = x[][] = x[][] = x[][] = ;
a[][] = ; a[][] = ;
matrix c_p = mat_pow(x, n - );
c_p = mat_mul(c_p, a);
matrix y(, vector<ll>(, )), b1(, vector<ll>(, )), b2(, vector<ll>(, )), b3(, vector<ll>(, ));
y[][] = y[][] = y[][] = y[][] = y[][] = ;
b1[][] = b2[][] = b3[][] = ;
matrix t = mat_pow(y, n - );
matrix f1_p = mat_mul(t, b1);
matrix f2_p = mat_mul(t, b2);
matrix f3_p = mat_mul(t, b3);
ll ans = ;
ans = ans * pow(c, c_p[][]) % mod;
ans = ans * pow(f1, f1_p[][]) % mod;
ans = ans * pow(f2, f2_p[][]) % mod;
ans = ans * pow(f3, f3_p[][]) % mod;
cout << ans << endl;
}
return ;
}

CF1182E Product Oriented Recurrence的更多相关文章

  1. cf 1182 E - Product Oriented Recurrence

    当时脑残了, 不会写矩阵快速幂中更改的系数, 其实把他扔到矩阵里同时递推就好了 #include<cstdio> #include<algorithm> #include< ...

  2. Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)

    传送门 题目 \[ \begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{aligned} \] 思路 我们通过迭代发 ...

  3. codeforces 1182E Product Oriented Recurrence 矩阵快速幂

    题意:设f(n) = c ^ (2n - 6) * f(n - 1) * f(n - 2) * f(n - 3), 问第n项是多少? 思路:官方题解:我们先转化一下,令g(x) =  c ^ x * ...

  4. CodeForces 1182E Product Oriented Recurrence

    题意 给定五个整数 \(n,f_1,f_2,f_3,c\),其中数列 \(f\) 满足以下递推式: \[f_x=c^{2x-6}f_{x-1}f_{x-2}f_{x-3} \] 求 \(f_n\). ...

  5. Codeforces Round #566 (Div. 2)

    Codeforces Round #566 (Div. 2) A Filling Shapes 给定一个 \(3\times n\) 的网格,问使用 这样的占三个格子图形填充满整个网格的方案数 如果 ...

  6. Codeforces Round #566 (Div. 2)题解

    时间\(9.05\)好评 A Filling Shapes 宽度为\(3\),不能横向填 考虑纵向填,长度为\(2\)为一块,填法有两种 如果长度为奇数则显然无解,否则\(2^{n/2}\) B Pl ...

  7. Into concurrent LRU caching once again

    But this time, with a more product oriented point of view, instead of researching. http://openmymind ...

  8. Face recognition using Histograms of Oriented Gradients

    Face recognition using Histograms of Oriented Gradients 这篇论文的主要内容是将Hog算子应用到人脸识别上. 转载请注明:http://blog. ...

  9. Goal Oriented Action Planning for a Smarter AI

    Goal Oriented Action Planning for a Smarter AI by Brent Owens23 Apr 2014 Goal Oriented Action Planni ...

随机推荐

  1. 在PCL中如何实现点云压缩(1)

    点云由庞大的数据集组成,这些数据集通过距离.颜色.法线等附加信息来描述空间三维点.此外,点云能以非常高的速率被创建出来,因此需要占用相当大的存储资源,一旦点云需要存储或者通过速率受限制的通信信道进行传 ...

  2. HTML基础:

    HTML是英文HyperText Markup Language的缩写,即超级文本标记语言,是用于描述网页文档的一种标记语言.HTMl是目前网络上应用最为广泛的语言,也是构成网页文档的主要语言.HTM ...

  3. 1、perl学习

    1.字符串函数 print chomp chop length uc lc index ord #转符号为ASCII的数字 chr #转数字为ASCII的字母 substr($string,offse ...

  4. JavaScript: 高级技巧: window 对象也可以添加自定义属性

    JavaScript: 高级技巧: window 对象也可以添加自定义属性 例如 window.ntName = 'a';例如 window.ntXw = top; 优点是, window 无须等加载 ...

  5. 18. CTF综合靶机渗透(十一)

    靶机描述: SkyDog Con CTF 2016 - Catch Me If You Can 难度:初学者/中级 说明:CTF是虚拟机,在虚拟箱中工作效果最好.下载OVA文件打开虚拟框,然后选择文件 ...

  6. SQL查询 若为空显示默认值

    COALESCE(a.end_,now()) SELECT COALESCE(NULL,NULL,3,4,5) FROM

  7. Note: File Recipe Compression in Data Deduplication Systems

    Zero-Chunk Suppression 检测全0数据块,将其用预先计算的自身的指纹信息代替. Detect zero chunks and replace them with a special ...

  8. Redis源码分析-底层数据结构盘点

    前段时间翻看了Redis的源代码(C语言版本,Git地址:https://github.com/antirez/redis), 过了一遍Redis数据结构,包括SDS.ADList.dict.ints ...

  9. BZOJ 1858【线段树】

    题意:  0 a b 把 [a, b] 区间内的所有数全变成0  1 a b 把 [a, b] 区间内的所有数全变成1  2 a b 把 [a,b] 区间内的所有数全部取反  3 a b 询问 [a, ...

  10. HyperLedger Explore 浏览器配置启动教程

    Hyperledger Fabric维护的实际上是一个区块链网络.为了能够直观的观察网络上的节点,交易等行为,Hyperledger Explore随之诞生. 本文讲述如何搭建 Hyperledger ...