[NOI2012]随机数生成器 矩阵乘法
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;
}
[NOI2012]随机数生成器 矩阵乘法的更多相关文章
- Bzoj 2875: [Noi2012]随机数生成器(矩阵乘法)
2875: [Noi2012]随机数生成器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 2052 Solved: 1118 Description ...
- BZOJ-2875 随机数生成器 矩阵乘法快速幂+快速乘
题目没给全,吃X了... 2875: [Noi2012]随机数生成器 Time Limit: 10 Sec Memory Limit: 512 MB Submit: 1479 Solved: 829 ...
- BZOJ 2875: [Noi2012]随机数生成器( 矩阵快速幂 )
矩阵快速幂...+快速乘就OK了 ----------------------------------------------------------------------------------- ...
- [vijos1725&bzoj2875]随机数生成器<矩阵乘法&快速幂&快速乘>
题目链接:https://vijos.org/p/1725 http://www.lydsy.com/JudgeOnline/problem.php?id=2875 这题是前几年的noi的题,时间比较 ...
- [luogu2044][NOI2012] 随机数生成器 [矩阵快速幂]
题面: 传送门 思路: 看一眼这个公式: $x\left[n+1\right]=\left(a\ast x\left[n\right]+c\right) mod m$ 递推,数据范围$n\leq 10 ...
- [日常摸鱼]bzoj2875[NOI2012]随机数生成器-矩阵快速幂
好裸的矩阵快速幂-然而我一开始居然构造不出矩阵- 平常两个的情况都是拿相邻两项放在矩阵里拿去递推的-然后我就一直构造不出来-其实把矩阵下面弄成1就好了啊orz #include<cstdio&g ...
- 矩阵(快速幂):COGS 963. [NOI2012] 随机数生成器
963. [NOI2012] 随机数生成器 ★★ 输入文件:randoma.in 输出文件:randoma.out 简单对比 时间限制:1 s 内存限制:128 MB [问题描述] 栋 ...
- [NOI2012]随机数生成器【矩阵快速幂】
NOI2012 随机数生成器 题目描述 栋栋最近迷上了随机算法,而随机数是生成随机算法的基础.栋栋准备使用线性同余法(Linear Congruential Method)来生成一个随机数列,这种方法 ...
- BZOJ2875 [Noi2012]随机数生成器 【矩阵乘法 + 快速乘】
题目 栋栋最近迷上了随机算法,而随机数是生成随机算法的基础.栋栋准备使用线性同余法(Linear Congruential Me thod)来生成一个随机数列,这种方法需要设置四个非负整数参数m,a, ...
随机推荐
- Reroute Unassigned Shards——遇到主shard 出现的解决方法就是重新路由
Red Cluster! 摘自:http://blog.kiyanpro.com/2016/03/06/elasticsearch/reroute-unassigned-shards/ There a ...
- [雅礼NOIP集训 2017] number 解题报告 (组合数+二分)
题解: 令$S(i)={i+1,i+2,...,i<<1}$,f(i,k)表示S(i)中在二进制下恰好有k个1的数的个数 那么我们有$f(i,k)=\sum_{x=1}^{min(k,p) ...
- 新手村,学会做人选数 https://www.luogu.org/problemnew/show/P1036
#include<cstdio> #include<cmath> #include<string.h> using namespace std; int n,k,s ...
- string的一些操作
//str.insert(1, "bbb"); //str.erase(5);//删除5以后的数字 //str.erase(str.begin()+2);//删除某个字符 //co ...
- oracle 11g not in 与not exists 那个高效?
网络上很多谣言是后面跟小表用not in,后面跟大表用not exists,难道真的是这样子的嘛? 情况下面测试: 1.先用小表测试(1000条记录和一张8万条记录的表): SQL> creat ...
- URAL 1297 后缀数组+线段树
思路: 论文题--*n 倒过来接上 分奇偶讨论 求LCP 搞棵线段树即可 //By SiriusRen #include <cstdio> #include <cstring> ...
- jq 方法函数(淡入淡出,查找元素,过滤)遍历
淡入淡出:fadeIn fadeOut fadeToggle fadeTo 淡入:fadeIn(speed[,callback]) 速度和回调函数 回调函数可以写匿名函数,或者方法名不加括号. s ...
- 你不知道的JavaScript博文参考书籍
you don't know js系列书籍是谷歌地图开发人员编写,内容非常好,四卷已收集齐全. 笔者打包上传到了CSDN,下载地址: http://download.csdn.net/detail/r ...
- Converting Legacy Chrome IPC To Mojo
Converting Legacy Chrome IPC To Mojo Looking for Mojo Documentation? Contents Overview Deciding What ...
- Pytorch搭建简单神经网络 Task2
1>建立数据集(并绘制图像) # -*- coding: utf-8 -*- #demo.py import torch import torch.nn.functional as F # 主要 ...