Code:

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
void setIO(string a){ freopen((a+".in").c_str(),"r",stdin); }
#define ll long long
ll mod,g;
int nodes;
struct matrix{
long long mat[2][2];
}unit,solve,fin;
void init(matrix &a){
for(int i=0;i<=nodes;++i)
for(int j=0;j<=nodes;++j) a.mat[i][j]=0;
}
void get(matrix &a){
init(a);
for(int i=0;i<=nodes;++i) a.mat[i][i]=1;
}
ll mult(ll a,ll b){
ll res=0;
while(b>0){
if(b&1) res=(res+a)%mod;
a=(a+a)%mod;
b>>=1;
}
return res;
}
matrix operator*(matrix a,matrix b){
matrix c;
init(c);
for(int i=0;i<=nodes;++i)
for(int j=0;j<=nodes;++j)
for(int k=0;k<=nodes;++k)
c.mat[i][j]=(c.mat[i][j]+mult(a.mat[i][k],b.mat[k][j]))%mod;
return c;
}
matrix operator^(matrix a,ll p){
matrix res;
get(res);
while(p>0){
if(p&1) res=res*a;
a=a*a;
p>>=1;
}
return res;
}
int main(){
//setIO("input");
nodes=1;
ll a,c,x,n;
cin>>mod>>a>>c>>x>>n>>g;
init(unit),init(solve);
unit.mat[0][0]=a,unit.mat[1][1]=1,unit.mat[1][0]=c;
solve.mat[0][0]=x,solve.mat[0][1]=1;
fin=solve*(unit^n);
cout<<(fin.mat[0][0]%mod)%g;
return 0;
}

  

最新文章

  1. 学习C++.Primer.Plus 10 对象和类
  2. Spring中scope作用域
  3. 图像预处理第9步:存为.bmp文件
  4. Winsock 入门 判读主机字节序 示例
  5. &lt;转&gt;Oracle SQL性能优化
  6. mysql 修改字段类型
  7. jquery 监控文本框键盘事件(回车事件),附常用keycode值。
  8. Android之列表内容显示
  9. .NET使用QRCodeEncoder生成二维码
  10. git Bug分支
  11. SQL Server 版本号汇总
  12. 2017-3-10 SQL server 数据库 T--SQL语句
  13. seajs模块标识命名和解析规则
  14. jira7.3.6 linux安装
  15. centos 7部署openvpn easy-rsa 3.0部署方法
  16. QDialog对话框
  17. ./configure: error: the HTTP rewrite module requires the PCRE library解决
  18. Delphi: Class Static Methods
  19. CURLOPT_RETURNTRANSFER
  20. 用Copy命令合并文件

热门文章

  1. event内存泄漏
  2. java web项目中资源国际化
  3. 关于lncRNA数据收集
  4. Pharmaceutical的同学们都看过来,关于补码运算的复习相关内容
  5. Codeforces 987B. High School: Become Human
  6. php正则检测字符串由单一字符组成
  7. c#学习0216
  8. [NOI2015]品酒大会(后缀树+DP)
  9. luogu P3414 SAC#1 - 组合数(组合数学)
  10. Spring 整合Shiro:记住我