思路:

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. 关于SCANF 与 GETS(C语言)

    SCANF遇到空格会自动停止录入字符串,而GETS不会,GETS可以用于输入带空格的字符串

  2. Shrio00 Shiro认证登录、权限管理环境搭建

    基础环境准备: JDK -> java version "1.8.0_101" MAVEN -> Apache Maven 3.5.0 1 导入依赖 mysql驱动 m ...

  3. CSS定位机制总结

    1,CSS 有三种基本的定位机制:普通流.浮动和绝对定位.除非专门指定,否则所有框都在普通流中定位.2,普通流定位:块级框从上到下一个接一个地排列,框之间的垂直距离是由框的垂直外边距计算出来.行内框在 ...

  4. hdu1069

    #include <iostream> #include <algorithm> #include <cstring> using namespace std; c ...

  5. jquery获取ASP.NET服务器端控件dropdownlist和radiobuttonlist生成客户端HTML标签后的value和text值

    —.获取dropdownlist的text(ddlList为服务器端dropdownlist的ID,生成name属性等于ddlList的select标签) $("#ddlList optio ...

  6. 【并发编程】Future模式添加Callback及Promise 模式

    Future Future是Java5增加的类,它用来描述一个异步计算的结果.你可以使用 isDone 方法检查计算是否完成,或者使用 get 方法阻塞住调用线程,直到计算完成返回结果.你也可以使用  ...

  7. Kolla Ocata版本安装及镜像制作流程

    1.关闭宿主机firewalldsystemctl disable firewalldsystemctl stop firewalld 2.配置selinux为disable,否则创建的实例网络不通临 ...

  8. foreach 加 &

  9. SAS笔记(1) PDV与数据读入

    其实我是不喜欢SAS的.当然,我不喜欢她,并不代表她不好,实际上在某些应用场景下SAS是款很优秀的软件.我的数据分析之路始于R,品尝过R的灵活与简洁(不论是软件安装还是语法)后,再来学习SAS,的确提 ...

  10. 清北刷题冲刺 10-31 a.m

    集合 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; ], ...