hdu4565


#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std;
long long aa,bb,n,mod,tt;
double t;
struct matrix{
long long a[];
long long b[][];
matrix operator *(const matrix&c)const{
matrix r;
For(i,,)
For(j,,){
r.b[i][j]=;
For(k,,)
r.b[i][j]=(r.b[i][j]+b[i][k]*c.b[k][j]%mod)%mod;
}
return r;
}
}a; void in(long long &x){
long long y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(long long x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
} matrix ksm(matrix a,long long b){
matrix r=a;
b--;
if(b==) return r;
while(b%==){
a=a*a;
b>>=;
}
while(b>){
if(b%==)
r=r*a;
a=a*a;
b>>=;
}
return r;
} int main(){
while(cin>>aa>>bb>>n>>mod){
if(n==){
o((long long)%mod);p('\n');
continue;
}
a.a[]=;
a.a[]=;
a.b[][]=aa%mod;
a.b[][]=bb%mod;
a.b[][]=;
a.b[][]=aa%mod;
matrix r,ans;
r=ksm(a,n);
For(i,,){
ans.a[i]=;
For(k,,)
ans.a[i]=(ans.a[i]+a.a[k]*r.b[i][k]%mod)%mod;
}
tt=;
tt=(tt+ans.a[])%mod;
o((*tt%mod+mod)%mod);p('\n');
}
return ;
}
hdu4565的更多相关文章
- 【HDU4565】So Easy!
[HDU4565]So Easy! 题面 要你求 \[ \lceil (a+\sqrt b)^n \rceil \% m \] 其中\(0<a,m<2^{15},(a-1)^2<b& ...
- HDU2256&&HDU4565:给一个式子的求第n项的矩阵快速幂
HDU2256 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2256 题意:求(sqrt(2)+sqrt(3))^2n%1024是多少. 这个题算是h ...
- HDU4565 So Easy! —— 共轭构造、二阶递推数列、矩阵快速幂
题目链接:https://vjudge.net/problem/HDU-4565 So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- HDU4565 So Easy!
/* HDU4565 So Easy! http://acm.hdu.edu.cn/showproblem.php?pid=4565 数论 快速幂 矩阵快速幂 题意:求[(a+sqrt(b))^n ] ...
- (转载)HDU4565
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4565 这个博客讲的比较好:http://blog.csdn.net/ljd4305/article/d ...
- HDU4565 && 2013年长沙邀请赛A题
部分转自http://blog.csdn.net/crazy______/article/details/9021169 #include<cstdio> using namespace ...
- hdu4565 So Easy! 矩阵快速幂
A sequence Sn is defined as: Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example ...
- HDU4565(SummerTrainingDay05-C 矩阵快速幂)
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- hdu4565矩阵快速幂
这题太坑了...刚开始以为可以用|a+sqrt(b) 1|水过...结果tle,还一直想明明我logn的做法怎么可能tle.. | 0 1| 实在无奈看的题解 (a+sqr ...
- hdu4565(矩阵快速幂+经典的数学处理)
注意题目的一个关键条件(a-1)2< b < a2 , 于是可以知道 0 < a-√b < 1 ,所以 (a-√b)^n < 1 . 然后 (a+ √b)^n+(a ...
随机推荐
- Hadoop 2.x 版本中的依赖 jar
- passwd的使用例子
passwd 作为普通用户和超级权限用户都可以运行,但作为普通用户只能更改自己的用户密码,但前提是没有被root用户锁定:如果root用户运行passwd ,可以设置或修改任何用户的密码: passw ...
- RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more infor
在virtualenv环境下使用matplotlib绘图时遇到了这样的问题: >>> import matplotlib.pyplot as pltTraceback (most r ...
- Array.prototype.splice()
splice() 方法通过删除或替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容.此方法会改变原数组. 在1位置上添加一项 我们没有下标为4的项,这个超了,就在最大项后面添加这 ...
- 【JZOJ3379】查询
description 对于一个整数序列,查询区间第k大数可以在O(logN)的时间内轻松完成.现在我们对这个问题进行推广. 考虑带重复数的集合(multiset).定义在该类集合上的并操作" ...
- 杂项-公司:IBM
ylbtech-杂项-公司:IBM IBM (IT公司-国际商业机器公司) IBM(国际商业机器公司)或万国商业机器公司,简称IBM(International Business Machines C ...
- topology进程结束会不会关闭数据库连接
测试环境:redhat,oracle 11.2.0.3.0 测试目标:当java进程关闭之后,进程的数据库连接会不会被释放,何时被释放 实验证明:在运行topology前,执行 select coun ...
- Python学习day34-面向对象和网络编程总结
figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { position: relative; } img { max- ...
- scrapy中的ImagePipeline下载图片到本地、并提取本地的保存地址
通过scrapy内置到ImagePipeline下载图片到本地 在settings中打开 ITEM_PIPELINES的注释,并在这里面加入 'scrapy.pipelines.images.Imag ...
- FPFH+ICP点云配准
A, UniformSampling降噪 B, ISS计算关键点, FPFH特征 在FeatureCloud::setInputCloud中读入点云,并调用processInput进行处理: proc ...