POJ 3070 + 51Nod 1242 大斐波那契数取余
2024-08-26 12:24:50
#include "iostream"
#include "cstdio"
using namespace std; class matrix
{
public:
int a[][];
matrix()
{
a[][]=a[][]=a[][]=;
a[][]=;
}
}; matrix multi(matrix a,matrix b)
{
matrix temp;
int i,j,k;
for(i=;i<;i++)
for(j=;j<;j++)
{
temp.a[i][j]=;
for(k=;k<;k++)
temp.a[i][j]+=(a.a[i][k]*b.a[k][j]);
temp.a[i][j]%=;
}
return temp;
} matrix power(int n)
{
matrix temp,s;
temp.a[][]=temp.a[][]=;
temp.a[][]=temp.a[][]=;
while(n!=)
{
if(n%!=)
temp=multi(temp,s);
s=multi(s,s);
n=n/;
}
return temp;
} int main()
{
int n;
while(~scanf("%d",&n)&&(n!=-))
{ matrix t=power(n);
cout<<t.a[][]<<endl;
}
return ;
}
#include "iostream"
#include "cstdio"
using namespace std;
#define MOD 1000000009
#define LL long long
class matrix
{
public:
LL a[][];
matrix()
{
a[][]=a[][]=a[][]=;
a[][]=;
}
}; matrix multi(matrix a,matrix b)
{
matrix temp;
LL i,j,k;
for(i=;i<;i++)
for(j=;j<;j++)
{
temp.a[i][j]=;
for(k=;k<;k++)
temp.a[i][j]+=(a.a[i][k]*b.a[k][j]);
temp.a[i][j]%=MOD;
}
return temp;
} matrix power(LL n)
{
matrix temp,s;
temp.a[][]=temp.a[][]=;
temp.a[][]=temp.a[][]=;
while(n!=)
{
if(n%!=)
temp=multi(temp,s);
s=multi(s,s);
n=n/;
}
return temp;
} int main()
{
LL n;
while(~scanf("%lld",&n)&&(n!=-))
{ matrix t=power(n);
cout<<t.a[][]<<endl;
}
return ;
}
最新文章
- caffe添加自己的层
- Python Virtualenv运行Django环境配置
- android TextView多行文本(超过3行)使用ellipsize=";end";属性无效问题的解决方法
- SQL---Chapter01 数据库和SQL
- redis/php redis扩展 安装
- IE奇怪报错
- C++实现不能被继承的类——终结类 分类: C/C++ 2015-04-06 14:48 64人阅读 评论(0) 收藏
- linux服务之tuned
- 内存修改console
- BZOJ2253: [2010 Beijing wc]纸箱堆叠
- [未完成]关于java基础数据类型中的一些总结
- jqery选择器
- Python数据类型转换
- ubuntu错误解决。
- winfrom运用webservice上传文件到服务器
- JavaSE学习总结第21天_IO流3
- Jquery操作Table
- .Net利用Newtonsoft进行解析Json的快捷方法
- HDFS深度历险 之 从客户端逻辑看HDFS写入机制
- 去掉手机端延迟300ms
热门文章
- 13 ThreadLocal
- 保证IO流不出错
- Node.js的require()的工作原理
- android4.1 Wifi 浅析
- MySql数据库插入或更新报错:Cannot add or update a child row: a foreign key constraint fails
- MySQL初识3
- 基于JWT的无状态分布式授权【本文摘自智车芯官网】
- onkeypress,onkeyup,onkeydown区别
- perf 对两个map是否重叠的判断,以及函数map_groups__fixup_overlappings代码逻辑
- Java 对象及其内存控制