Reading comprehension HDU
来源:互联网 发布:进销存哪种软件好 编辑:程序博客网 时间:2024/06/06 02:24
Reading comprehension HDU - 4990
Read the program below carefully then answer the question.
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include<iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include<vector>
const int MAX=100000*2;
const int INF=1e9;
int main()
{
int n,m,ans,i;
while(scanf("%d%d",&n,&m)!=EOF)
{
ans=0;
for(i=1;i<=n;i++)
{
if(i&1)ans=(ans*2+1)%m;
else ans=ans*2%m;
}
printf("%d\n",ans);
}
return 0;
}
[Technical Specification]
1<=n, m <= 1000000000
1 103 100
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<string>#include<cstdio>#include<cstring>#include<cmath>#include<iostream>#include<queue>#include<stack>#include<vector>#include<set>#include<algorithm>#define maxn 10010#define INF 0x3f3f3f3f#define eps 1e-8#define MOD 1000000007#define ll long longusing namespace std;ll mod;struct Node{ ll mat[3][3];};Node mul(Node a,Node b){ Node ret; memset(ret.mat,0,sizeof ret.mat); for(int i=0;i<3;++i) for(int j=0;j<3;++j) { ret.mat[i][j]=0; for(int k=0;k<3;++k) ret.mat[i][j]=(ret.mat[i][j]+a.mat[i][k]*b.mat[k][j]%mod+mod)%mod; } return ret;}Node Pow(Node a,ll n){ Node ret; memset(ret.mat,0,sizeof(ret.mat)); for(int i=0;i<3;++i) ret.mat[i][i]=1; Node tmp=a; while(n) { if(n&1)ret=mul(ret,tmp); tmp=mul(tmp,tmp); n>>=1; } return ret;}int main(){ ll n,m; Node A; memset(A.mat,0,sizeof A.mat); A.mat[0][0]=A.mat[0][2]=A.mat[1][0]=A.mat[2][2]=1; A.mat[0][1]=2; Node B; memset(B.mat,0,sizeof B.mat); B.mat[0][0]=1;B.mat[1][0]=0;B.mat[2][0]=1; while(scanf("%lld%lld",&n,&m)!=EOF) { mod=m; Node ans; memset(ans.mat,0,sizeof ans.mat); ans=mul(Pow(A,n-1),B); printf("%lld\n",ans.mat[0][0]); } return 0;}
阅读全文
0 0
- hdu 4990 Reading comprehension
- hdu 4990 Reading comprehension
- hdu 4990 Reading comprehension
- HDU 4990 Reading comprehension
- HDU 4990 Reading comprehension
- HDU 4990 Reading comprehension
- hdu 4990 Reading comprehension
- Reading comprehension HDU
- hdu-4990 Reading comprehension
- Reading comprehension HDU
- HDU 4990 Reading comprehension
- Reading comprehension HDU
- hdu 4990 Reading comprehension (矩阵快速幂)
- hdu 4990 Reading comprehension(矩阵快速幂)
- hdu 4990 Reading comprehension(矩阵法)
- [矩阵快速幂] hdu 4990 Reading comprehension
- hdu 4990 Reading comprehension(等比数列法)
- HDU - 4990 Reading comprehension (矩阵快速幂)
- POS银联PCI认证
- 详解kafka集群搭建
- HDU 6183 Color it(线段树+思维+高端的优化技巧)
- Mybatis+JDBC 实现单表增删改查
- Java读取大文件的高效率实现
- Reading comprehension HDU
- PCB设计经验「精辟」
- tar: bzip2:无法 exec: 没有那个文件或目录
- BootStrap学习记录
- UIViewController_Swizzled的原理和使用
- struts2 属性文件乱码解决
- 树——二叉树层序遍历
- How to be a Big data Master step 1
- 新手来报道