杭电多校第七场 1010 Sequence(除法分块+矩阵快速幂)
Sequence Problem Description Let us define a sequence as below f1=A f2=B fn=C*fn-2+D*fn-1+[p/n] Your job is simple, for each task, you should output F n module 10 9 + 7 . Input The first line has only one integer T , indicates the number of tasks. Then, for the next T lines, each line consists of 6 integers, A , B , C , D , P , n . 1 ≤ T ≤ 20 0 ≤ A , B , C , D ≤ 10 9 1 ≤ P , n ≤ 10 9 Sample Input 2 3 3 2 1 3 5 3 2 2 2 1 4 Sample Output 36 24 题意:题目给出ABCDPn,第一项是A,第二项是B,然后还有个递推式,问第n项是多少 思路:如果我们按照他的递推式去推得答案的话,n的范围是1e9肯定会超时,但是我们又必须要用到这个式子,我们就想有没有加快的方法,其实做多了题会发现这是矩阵快速幂的形式 矩阵快速幂就是把你原有的递推式再加快执行, 但是 fn