Another kind of Fibonacci

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1919    Accepted Submission(s): 738

Problem Description

As we all known , the Fibonacci series : F(0) = 1, F(1) = 1, F(N) = F(N - 1) + F(N - 2) (N >= 2).Now we define another kind of Fibonacci : A(0) = 1 , A(1) = 1 , A(N) = X * A(N - 1) + Y * A(N - 2) (N >= 2).And we want to Calculate S(N) , S(N) = A(0)2 +A(1)2+……+A(n)2.

 
Input
There are several test cases.
Each test case will contain three integers , N, X , Y .
N : 2<= N <= 231 – 1
X : 2<= X <= 231– 1
Y : 2<= Y <= 231 – 1
 
Output
For each test case , output the answer of S(n).If the answer is too big , divide it by 10007 and give me the reminder.
 
Sample Input
2 1 1
3 2 3
 
Sample Output
6
196
 

题意:很明确了。。。不多说。

思路:

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3306

转载请注明出处:寻找&星空の孩子

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define LL __int64
#define mod 10007 struct matrix
{
LL mat[][];
}; matrix multiply(matrix a,matrix b)
{
matrix c;
memset(c.mat,,sizeof(c.mat));
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
if(a.mat[i][j]==)continue;
for(int k=;k<;k++)
{
if(b.mat[j][k]==)continue;
c.mat[i][k]=(c.mat[i][k]+a.mat[i][j]*b.mat[j][k])%mod;
}
}
}
return c;
} matrix quickmod(matrix a,LL n)
{
matrix res;
for(int i=;i<;i++)
for(int j=;j<;j++)
res.mat[i][j]=(i==j);
while(n)
{
if(n&) res=multiply(res,a);
n>>=;
a=multiply(a,a);
}
return res;
} int main()
{
LL n,x,y; while(scanf("%I64d%I64d%I64d",&n,&x,&y)!=EOF)
{
if(n==||n==)
{
printf("%I64d\n",n+);
continue;
}
matrix ans;
ans.mat[][]=ans.mat[][]=;
ans.mat[][]=ans.mat[][]=ans.mat[][]=;
ans.mat[][]=ans.mat[][]=ans.mat[][]=;
ans.mat[][]=ans.mat[][]=x*x%mod;
ans.mat[][]=ans.mat[][]=y*y%mod;
ans.mat[][]=ans.mat[][]=*x*y%mod;
ans.mat[][]=x%mod;
ans.mat[][]=y%mod; ans=quickmod(ans,n-);
printf("%I64d\n",(*ans.mat[][]+ans.mat[][]+ans.mat[][]+ans.mat[][])%mod); }
return ;
}

加油!少年!

Another kind of Fibonacci(矩阵)的更多相关文章

  1. hdu 1588(Fibonacci矩阵求和)

    题目的大意就是求等差数列对应的Fibonacci数值的和,容易知道Fibonacci对应的矩阵为[1,1,1,0],因为题目中f[0]=0,f[1]=1,所以推出最后结果f[n]=(A^n-1).a, ...

  2. BZOJ3286 Fibonacci矩阵 矩阵 快速幂 卡常

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ3286 题意概括 n,m,a,b,c,d,e,f<=10^1000000 题解 神奇的卡常题目 ...

  3. POJ3070 Fibonacci[矩阵乘法]

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Descri ...

  4. 【全国互虐】Fibonacci矩阵

    orz啊又被屠了 人生如此艰难 题意: 给定一个k维的n^k的超立方体 超立方体的元素Ai1,i2,...,ik 的值为f(i1+i2+...+ik-k+1) f为斐波那契数列 求该超立方体的所有元素 ...

  5. poj 3070 Fibonacci (矩阵快速幂乘/模板)

    题意:给你一个n,输出Fibonacci (n)%10000的结果 思路:裸矩阵快速幂乘,直接套模板 代码: #include <cstdio> #include <cstring& ...

  6. poj 3070 Fibonacci 矩阵快速幂

    Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. F ...

  7. HDU 3306 Another kind of Fibonacci(矩阵+ll超时必须用int&输入必须取模&M必须是int类型)

    Another kind of Fibonacci [题目链接]Another kind of Fibonacci [题目类型]矩阵+ll超时必须用int&输入必须取模&M必须是int ...

  8. POJ3070 Fibonacci[矩阵乘法]【学习笔记】

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Descri ...

  9. HDU 1588 Gauss Fibonacci(矩阵快速幂)

    Gauss Fibonacci Time Limit: 3000/1000 MS (Java/Others)     Memory Limit: 32768/32768 K (Java/Others) ...

  10. HDU1588-Gauss Fibonacci(矩阵高速幂+等比数列二分求和)

    题目链接 题意:g(x) = k * x + b.f(x) 为Fibonacci数列.求f(g(x)),从x = 1到n的数字之和sum.并对m取模. 思路:  设A = |(1, 1),(1, 0) ...

随机推荐

  1. WPF TreeView BringIntoViewBehavior

    由于项目需要,需要能够定位TreeView中的点,TreeView的节点数过多的情况下,即使找到了对应的节点并选中展示了,由于不在可视区域内,给用户的感觉还是不好,因此设计如下的Behavior,来实 ...

  2. HttpClient的帮助类

    /// <summary> /// http请求类 /// </summary> public class HttpHelper { private HttpClient _h ...

  3. cnetos6上实现nfs共享

    利用空余时间,做个nfs共享实验,岂不美滋滋!!! 系统测试环境: 主机ip 系统     主机名(服务) 192.168.241.130    centos6.5    hadoop1(nfs-sr ...

  4. captcha ~ 生成验证码图片

    验证码在我们的世界中可以保护我们的信息安全的一个保障之一 这就是生成验证码的代码     # 导报 from captcha.image import ImageCaptcha #验证码的包 from ...

  5. Quartz深入浅出(一)

    什么是Quartz Quartz是一个开源的作业调度框架,由java编写,在.NET平台为Quartz.Net,通过Quart可以快速完成任务调度的工作. Quartz能干什么/应用场景 如网页游戏中 ...

  6. SQLAlchemy 快速入门、基础知识

    SQLAlchemy 是Python 编程语言下的一款开源软件.提供了SQL工具包及对象关系映射(ORM)工具. ORM, 全称Object Relational Mapping, 中文叫做对象关系映 ...

  7. 07-01 Java 封装

    1:成员变量和局部变量的区别 /* 成员变量和局部变量的区别? A:在类中的位置不同 成员变量:在类中方法外 局部变量:在方法定义中或者方法声明上 B:在内存中的位置不同 成员变量:在堆内存 局部变量 ...

  8. 刚破了潘金莲的身份信息(图片文字识别),win7、win10实测可用(免费下载)

    刚破了潘金莲的身份信息(图片文字识别),win7.win10实测可用 效果如下: 证照,车牌.身份证.名片.营业执照 等图片文字均可识别 电脑版 本人出品 大小1.3MB 下载地址:https://p ...

  9. Unity使用Rider作为IDE的体验

    Rider 2017.2.1比较完整的支持Unity开发. 通过添加插件代码实现了直接选择Rider作为编辑器. 支持调试. 支持双击跳转代码. Alt+Insert可以插入Unity event函数 ...

  10. 课程一(Neural Networks and Deep Learning)总结——1、Logistic Regression

    ---------------------------------------------------------------------------------------------------- ...