hdu So Easy!
So Easy!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2026 Accepted Submission(s): 624

Where a, b, n, m are positive integers.┌x┐is the ceil of x. For example, ┌3.14┐=4. You are to calculate Sn.
You, a top coder, say: So easy!

#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef __int64 LL; LL p ;
struct Matrix
{
LL mat[][];
void init()
{
mat[][]=;mat[][]=;
mat[][]=;mat[][]=;
}
void mem(LL a,LL b)
{
mat[][]=(*a)%p; mat[][]=(b-a*a)%p;
mat[][]=; mat[][]=;
}
};
Matrix multiply(Matrix cur,Matrix ans)
{
Matrix now;
memset(now.mat,,sizeof(now.mat));
int i,j,k;
for(i=;i<=;i++)
{
for(k=;k<=;k++)
{
for(j=;j<=;j++)
{
now.mat[i][j]+=cur.mat[i][k]*ans.mat[k][j];
now.mat[i][j]%=p;
while(now.mat[i][j]<) now.mat[i][j]+=p;
}
}
}
return now;
}
void pow_mod(Matrix cur,LL n,LL a,LL b)
{
Matrix ans;
ans.init();
while(n)
{
if(n&) ans=multiply(ans,cur);
n=n>>;
cur=multiply(cur,cur);
}
LL sum=(ans.mat[][]**a+ans.mat[][]*)%p;
printf("%I64d\n",sum);
}
int main()
{
LL a,b,n;
while(scanf("%I64d%I64d%I64d%I64d",&a,&b,&n,&p)>)
{
Matrix hxl;
hxl.mem(a,b);
if(n>)
pow_mod(hxl,n-,a,b);
else printf("%I64d\n",(*a)%p);
}
return ;
}
hdu So Easy!的更多相关文章
- HDU 别easy在一系列的
别easy在一系列的 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Su ...
- HDU 5572--An Easy Physics Problem(射线和圆的交点)
An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/ ...
- HDU 4359——Easy Tree DP?——————【dp+组合计数】
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU——4565So Easy!(矩阵快速幂)
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- HDU 2601An easy problem-素数的运用,暴力求解
id=17433" target="_blank" style="color:blue; text-decoration:none">An ea ...
- HDU 5475An easy problem 离线set/线段树
An easy problem Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDU 4359 Easy Tree DP?
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 2015 Multi-University Training Contest 6 hdu 5357 Easy Sequence
Easy Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- ACM 2015年上海区域赛A题 HDU 5572An Easy Physics Problem
题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板, ...
随机推荐
- HDFS简介
Hadoop是当今最为流行的大数据分析和处理工具. 其最先的思想来源于Google的三篇论文: GFS(Google File System):是 ...
- JDBC工作模块
jdbc-->java数据库连接 的简称 JDBC工作模块 加载jdbc驱动 与数据库连接 发送sql语句,得到返回结果 处理返回结果 释放资源
- 转:Order&Shipping Transactions Status Summary
详细内容: http://blog.csdn.net/pan_tian/article/details/7696528 WSH_DELIVERY_DETAILS.Release_Status can ...
- FM000
SQL> select To_char(1,'000') from dual; TO_C----001 注意最左边有一个空格 SQL> select To_char(1,'FM000') ...
- windows下快速启动 nginx 和 php-cgi 的两个批处理
这是启动的批处理: set nginx=D:\nginx-1.9.5\ set php=D:\php\ start /MIN %nginx%nginx.exe start /MIN %php%php- ...
- html5的download下载标签
Html5的下载标签download <a href="files/1.jpg" download="1.jpg">Download</a&g ...
- SQL SERVER: 合并相关操作(Union,Except,Intersect) - 转载
SQL Server 中对于结果集有几个处理,值得讲解一下 1. 并集(union,Union all) 这个很简单,是把两个结果集水平合并起来.例如 SELECT * FROM A UNION SE ...
- dumpbin使用
声明一点:Win7系统,安装的是VS2010 dumpbin.exe位于C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin目录下. 初 ...
- Respond.js – 让 IE6-8 支持 CSS3 Media Query
Respond.js 是一个快速.轻量的 polyfill,用于为 IE6-8 以及其它不支持 CSS3 Media Queries 的浏览器提供媒体查询的 min-width 和 max-width ...
- Linux中文显示乱码解决
输入 echo $LANG可以查看当前使用的系统语言 查看是否有中文语言包可以在终端输入 locale命令,如有zh cn 表示已经安装了中文语言 没有则 yum groupinstall chine ...