http://blog.csdn.net/wust_xhj/article/details/47779539

怎么推可以看这里

f[0]=0

f[1]=1

[0,1]* | 0  q  |(n-1)=[f(n-1),f(n)]

     | 1 q-1|

跑一下快速幂

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h> using namespace std;
typedef long long ll;
#define MAXN 105 struct node
{
ll z[][];
};
ll Quick(ll a,ll b,ll c)
{
ll ans=;
while(b>)
{
if(b%==)
ans=(ans*a)%c;
b/=;
a=(a*a)%c;
}
return ans;
}
ll p;
node mou(node a,node b)
{
node c;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
ll sum=;
for(int k=;k<;k++)
sum=(sum+a.z[i][k]*b.z[k][j])%p;
c.z[i][j]=sum;
}
}
return c;
}
int main()
{
ll x1,y1,z1,y2,z2;
while(scanf("%lld%lld%lld",&x1,&y1,&z1)!=EOF)
{
if(x1==-&&y1==-&&z1==-)
break;
scanf("%lld%lld%lld",&y2,&z2,&p);
ll q=(Quick(x1,y1,p)+z1)%p;
node s,a,ans;
ans.z[][]=;
ans.z[][]=;
ans.z[][]=;
ans.z[][]=;
a.z[][]=;
a.z[][]=q;
a.z[][]=;
a.z[][]=q-;
s=a;
while(z2>)
{
if(z2%==)
ans=mou(ans,a);
z2=z2/;
a=mou(a,a);
}
for(int i=;i<y2;i++)
{
ans=mou(s,ans);
s=mou(s,s);
}
printf("%d\n",ans.z[][]); }
return ;
}

最新文章

  1. js 动态添加行,删除行,并获得select中值赋予 input
  2. 【原创】express3.4.8源码解析之路由中间件
  3. (转)Mono for Android 优势与劣势
  4. -_-#【Angular】定义服务
  5. 关于left join连接查询 两张表里有同名字段的问题
  6. [转]Visual Studio 2008中如何比较二个数据库的架构【Schema】和数据【Data】并同步
  7. JavaScript最全的10种跨域共享的方法
  8. nginx 配置访问限制
  9. liunx命令2
  10. Android --&gt; 常见控件
  11. java的static与C#的static的异同
  12. python 全栈开发,Day107(CRM初始,权限组件之权限控制,权限系统表设计)
  13. 使用PHPMailer 中的报错解决 &quot;Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:&quot;
  14. [PHP]PHP页面静态化:真静态的两种方案
  15. Lua的闭包详解(终于搞懂了)
  16. ArcGIS API 和GIServer
  17. o2o优惠券使用预测
  18. bzoj2595: [Wc2008]游览计划 斯坦纳树
  19. 四则运算 Java (于泽浩,袁浩越)
  20. rabbitmq集群配置

热门文章

  1. angular-JS模仿Form表单提交
  2. Navisworks 2014 Api 简单的使用
  3. ASP.NET MVC——Razor视图引擎
  4. JVM之内存结构
  5. 关于MySql的1045错误修正
  6. 报表或BI的价值在哪?
  7. python-open文件处理
  8. 5-2 bash 脚本编程之一 变量、变量类型等
  9. 数据库Sharding系列文章
  10. STM32 按键输入