HDU 6395 2018 Multi-University Training Contest 7 (快速幂+分块)

原题地址

Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1186    Accepted Submission(s): 433


Problem Description
Let us define a sequence as below

⎧⎩⎨⎪⎪⎪⎪⎪⎪F1F2Fn===ABCFn2+DFn1+Pn


  Your job is simple, for each task, you should output Fn module 109+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 , BCDPn.

1T200A,B,C,D1091P,n109
 

 

Sample Input
2 3 3 2 1 3 5 3 2 2 2 1 4
 

 

Sample Output
36 24
 

 

Source
2018 Multi-University Training Contest 7
 

 

Recommend
 
矩阵快速幂,但是中间带着一个跟着N变化的值;一开始想直接硬构造出一个矩阵;发现行不通就和队友搞其他题了;
后来发现这P/n在每个sqrt(q)范围内都是一定的;所以可以试着查找p/n这个值最大到哪一项,然后分别快速幂;很神奇的就是为什么p/(p/i)就是这个p/i的最大项;到现在还不明白‘
我的矩阵
 
Fn    D C p/i     Fn-1
Fn-1   1  0  0      Fn-2
1      0  0  1        1
代码:
#include
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=3e6+50;
const ll inf=0x3f3f3f3f3f3f;
ll a,b,c,d,p,n;
ll k,kk;
ll fun[100000005];
struct node{
    ll a[3][3];
    void init(){
        memset(a,0,sizeof(a));
        for(int i=0;i<3;i++){
            a[i][i]=1;
        }
    }
};
node mul(node a,node b)
{
    node ans;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            ans.a[i][j]=0;
            for(int k=0;k<3;k++){
                ans.a[i][j]+=a.a[i][k]*b.a[k][j];
                ans.a[i][j]%=mod;
            }
        }
    }return ans;
}
void output(node a){
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            cout<>t;
    while(t--){
        cin>>a>>b>>c>>d>>p>>n;
        k=p/n;kk=p%n;
        if(n==1){cout<

  

转载于:https://www.cnblogs.com/luowentao/p/9474575.html

你可能感兴趣的:(HDU 6395 2018 Multi-University Training Contest 7 (快速幂+分块))