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 ...
随机推荐
- Win10命令提示符git log中文乱码的解决方案
在系统环境变量中新建一个名为LESSCHARSET的变量 其值为utf-8 新建完毕后应用,git log就不会出现乱码的问题了^_^ 参考博文:git- win10 cmd git log 中文乱码 ...
- CentOS7-Minimal安装MySQL服务
CentOS7默认安装的是Mariadb而不是mysql,而Mariadb是mysql的一个分支, 安装mysql会覆盖Mariadb 一.下载MySQL官方的 Yum Repository [roo ...
- wpf datepicker 样式
在项目中用到的 <Style TargetType="{x:Type DatePicker}"> <Setter Property="Foregroun ...
- java_缓冲流(字符输出输入流)
/** java.io.BufferedReader extends Reader * * 构造方法: * BufferedReader(Reader in):创建一个使用默认大小输入缓冲区的缓冲字符 ...
- 用shell编写小九九乘法表程序
1.使用for循环 运行结果: 2.方法二:for循环 运行结果: 备注: 1. echo -n 的意思是不自动换行,因为在linux shell中 echo到最后一个字符时会自动换行的,所以echo ...
- ThinkPHP支持模型的分层
ThinkPHP支持模型的分层 ,除了Model层之外,我们可以项目的需要设计和创建其他的模型层. 大理石平台支架 通常情况下,不同的分层模型仍然是继承系统的\Think\Model类或其子类,所以, ...
- <数据链接>常用网站收集
1.互联网数据指数 百度指数:http://index.baidu.com/ 阿里指数:http://index.1688.com/ TBI腾讯浏览指数:http://tbi.tencent.com/ ...
- <随便写>佛祖,哈哈!
print(" _ooOoo_ ") print(" o8888888o ") print(" 88 . 88 ") print(" ...
- HDU--2191 汶川地震购米(多重背包)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2191 分析:有资金n元,而市场有m种大米,每种大米价格不等,重量不等,数量不等, 并且只能整袋购买.如何用 ...
- vue 实现邮戳边缘
效果: vue: <template> <div class="couponItem"> <div class="itemLeft" ...