POJ 3070

#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 ;
}

51Nod 1242 大斐波那契数取余

#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 ;
}

最新文章

  1. caffe添加自己的层
  2. Python Virtualenv运行Django环境配置
  3. android TextView多行文本(超过3行)使用ellipsize=&quot;end&quot;属性无效问题的解决方法
  4. SQL---Chapter01 数据库和SQL
  5. redis/php redis扩展 安装
  6. IE奇怪报错
  7. C++实现不能被继承的类——终结类 分类: C/C++ 2015-04-06 14:48 64人阅读 评论(0) 收藏
  8. linux服务之tuned
  9. 内存修改console
  10. BZOJ2253: [2010 Beijing wc]纸箱堆叠
  11. [未完成]关于java基础数据类型中的一些总结
  12. jqery选择器
  13. Python数据类型转换
  14. ubuntu错误解决。
  15. winfrom运用webservice上传文件到服务器
  16. JavaSE学习总结第21天_IO流3
  17. Jquery操作Table
  18. .Net利用Newtonsoft进行解析Json的快捷方法
  19. HDFS深度历险 之 从客户端逻辑看HDFS写入机制
  20. 去掉手机端延迟300ms

热门文章

  1. 13 ThreadLocal
  2. 保证IO流不出错
  3. Node.js的require()的工作原理
  4. android4.1 Wifi 浅析
  5. MySql数据库插入或更新报错:Cannot add or update a child row: a foreign key constraint fails
  6. MySQL初识3
  7. 基于JWT的无状态分布式授权【本文摘自智车芯官网】
  8. onkeypress,onkeyup,onkeydown区别
  9. perf 对两个map是否重叠的判断,以及函数map_groups__fixup_overlappings代码逻辑
  10. Java 对象及其内存控制