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