思路:

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. [matlab]机器学习及SVM工具箱学习笔记

    机器学习与神经网络的关系: 机器学习是目的,神经网络是算法.神经网络是实现机器学习的一种方法,平行于SVM. 常用的两种工具:svm tool.libsvm SVM分为SVC和SVR,svc是专门用来 ...

  2. 在Eclipse里面配置Struts2

    下面介绍在Eclipse里面配置Struts2 下载Struts2的压缩包 我下载的是2.3.32版本 解压之后如图所示 apps目录:Struts2的范例 docs目录:Struts2的文档 lib ...

  3. js 使用中一些需要提醒的点

    1.js 中可以直接使用输出java 变量 <script> var path = '<%=basePath%>'; 2.js重新注册事件后,如何让事件不自动执行? mzTxt ...

  4. redis学习总结1

    Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.和普通的Key-Value结构不同,Redis的Key支持灵活 ...

  5. C# EventHandler委托事件小结--百度

    最近遇到一个委托的问题,+=这个符号 this.Activated += new EventHandler(Form1_Activated);//Form1_Activated为方法名12 这个语句拆 ...

  6. 微信小程地图片未加载成功的情况 Failed to load local image resource

    在开发小程序的时候,发现在加载图片时并没有异常,但是后台却报错了. 例如以下我的一段代码: <view class="useage2 "> <image src= ...

  7. window下安装composer步骤(linux待研究)

    window下安装composer步骤--注意(安装完之后需要重启电脑才能生效) 转发:https://blog.csdn.net/wengedexiaozao/article/details/798 ...

  8. 我的省选 Day -11

    Day -11 上了一天的文化课,晚上才来到机房(神秘的一天.. 班里前一半的JuLao们都去参加省质检的同步赛了, 然而我太菜,早就跌到班级的中下下了(所以没得参加.. 所以今天上课时特别尴尬,班级 ...

  9. Jmeter_拦截Excel文件输出流到本地

    一般而言,对于页面的“导出”操作,主要经历如下两个操作:①根据数据库的内容,将文件导出到应用服务器上:②将服务器上的文件下载到本地电脑: Jmeter同LoadRunner类似,只能记录服务端与客户端 ...

  10. 8、kvm虚拟机添加硬盘

    kvm虚拟机添加硬盘qemu-img创建一块新的硬盘 qemu-img create -f qcow2 /kvm-data/kvm/jumperhost_disk1.qcow2 50G 关闭虚拟机 v ...