摘要:
这题属于矩阵构造,有a(n)=x*a(n-1)+y*a(n-2);s(n)=s(n-1)+a(n)^2;联立可得到相关矩阵,再用矩阵2分快速幂就可得到结果了……#include<iostream>#include<stdio.h>using namespace std;typedef __int64 int64;long x,y,n;const int mod=10007;struct matrix{ int64 a[4][4];};matrix e;matrix mul(matrix m,matrix n){ matrix ans; for(int i=0;i< 阅读全文
posted @ 2013-05-20 21:22
_随心所欲_
阅读(158)
评论(0)
推荐(0)
摘要:
这个挺不错的,要考虑的问题很多,首先是矩阵2分快速幂,再就是矩阵的求和。在矩阵的求和中要用到快速2分,采用递归来求……#include<iostream>#include<stdio.h>using namespace std;typedef __int64 int64;long k,b,n,mod;struct matrix{ int64 a[2][2]; void init() { a[0][0]=a[0][1]=a[1][0]=1; a[1][1]=0; } void e() { a[0][0]=a[1][1]=1; a[0][1]=a[1][0]=0; }};m 阅读全文
posted @ 2013-05-20 20:04
_随心所欲_
阅读(192)
评论(0)
推荐(0)
摘要:
这题很容易就可以推出f(n)的公式。这个用到了矩阵和整数的快速2分幂,还需注意一点就是pow(n,m)=pow(n,m mod 1000000006);千万注意别写成mod 1000000007 ,否者会一直WA的。#include<iostream>#include<stdio.h>using namespace std;typedef __int64 in;struct aa{ in a[2][2]; void init() { a[0][0]=a[0][1]=a[1][0]=1; a[1][1]=0; }};aa mul(aa m,aa n){ aa ans; f 阅读全文
posted @ 2013-05-20 14:24
_随心所欲_
阅读(266)
评论(0)
推荐(0)

浙公网安备 33010602011771号