博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4565So Easy!(巧妙的矩阵快速幂)
阅读量:4048 次
发布时间:2019-05-25

本文共 1607 字,大约阅读时间需要 5 分钟。

So Easy!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3849    Accepted Submission(s): 1266
Problem Description
  A sequence S
n is defined as:
Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate S
n.
  You, a top coder, say: So easy!
 
Input
  There are several test cases, each test case in one line contains four positive integers: a, b, n, m. Where 0< a, m < 2
15, (a-1)
2< b < a
2, 0 < b, n < 2
31.The input will finish with the end of file.
 
Output
  For each the case, output an integer S
n.
 
Sample Input
2 3 1 20132 3 2 20132 2 1 2013
 
Sample Output
4144
 
Source
 
Recommend
zhoujiaqi2010   |   We have carefully selected several similar problems for you:            
/*告诉你a,b,n,m,求0
<2^15 , (a-1)^2
#include
#include
using namespace std;typedef long long ll;struct matrix{ ll mat[2][2];};matrix mul(matrix &a,matrix &b,ll mm){ matrix c; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { c.mat[i][j]=0; for(int k=0;k<2;k++) { c.mat[i][j]+=(a.mat[i][k]*b.mat[k][j]); } c.mat[i][j]%=mm; } } return c;}matrix inti(){ matrix ans; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) ans.mat[i][j]=(i==j); } return ans;}matrix ks(matrix a,ll k,ll mm){ matrix ans=inti(); while(k) { if(k&1) ans=mul(ans,a,mm); a=mul(a,a,mm); k>>=1; } return ans;}int main(){ matrix M; ll a,b,n; ll m; while(~scanf("%lld%lld%lld%lld",&a,&b,&n,&m)) { M.mat[0][0]=a; M.mat[1][1]=a; M.mat[0][1]=b; M.mat[1][0]=1; matrix ans=ks(M,n,m); ll x=ans.mat[0][0]; cout<<(2*x)%m<

转载地址:http://aafci.baihongyu.com/

你可能感兴趣的文章
React Native(二):属性、状态
查看>>
JSX使用总结
查看>>
React Native(四):布局(使用Flexbox)
查看>>
React Native(七):Android双击Back键退出应用
查看>>
Android自定义apk名称、版本号自增
查看>>
adb command not found
查看>>
Xcode 启动页面禁用和显示
查看>>
【剑指offer】q50:树中结点的最近祖先
查看>>
二叉树的非递归遍历
查看>>
【leetcode】Reorder List (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Linked List Cycle (python)
查看>>
【leetcode】Candy(python)
查看>>
【leetcode】Clone Graph(python)
查看>>
【leetcode】Sum Root to leaf Numbers
查看>>
【leetcode】Pascal's Triangle II (python)
查看>>
java自定义容器排序的两种方法
查看>>
如何成为编程高手
查看>>
本科生的编程水平到底有多高
查看>>
AngularJS2中最基本的文件说明
查看>>