HDUOJ--4565 So Easy!
So Easy!
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1729 Accepted Submission(s): 556

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!


/*快速矩@ coder Gxjun*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
__int64 ma[][]; //matrix
__int64 ans[][];
void init(__int64 a[][])
{
int i;
for(i=;i<;i++)
a[i][i]=; //E 设置为1
a[][]=;
a[][]=;
}
int main()
{
int a,b,m,n,i,j,k;
__int64 temp[] ;
__int64 hop[][];
while(scanf("%d%d%d%d",&a,&b,&n,&m)!=EOF)
{
if(n==)
{
printf("%I64d\n",(*a)%m);
continue;
}
else if(n==)
{
printf("%I64d\n",(*(a*a+b))%m);
continue;
}
n-=;
init(ans);
/*init(ma);*/
ma[][]=(*a)%m;
ma[][]=(b-a*a)%m;
ma[][]=;
ma[][]=;
while(n>)
{
if(n&)
{
for(k=;k<;k++)
{
memset(temp,,sizeof(temp));
for(i=;i<;i++)
{
for(j=;j<;j++)
{
temp[i]+=ans[k][j]*ma[j][i];
temp[i]%=m;
}
}
ans[k][]=temp[];
ans[k][]=temp[];
}
n--;
continue;
}
memset(hop,,sizeof(hop));
for(k=;k<;k++)
{
for(i=;i<;i++)
{
for(j=;j<;j++)
{
hop[k][i]+=ma[k][j]*ma[j][i];
hop[k][i]%=m;
}
}
}
for(i=;i<;i++)
{
for(j=;j<;j++)
{
ma[i][j]=hop[i][j];
}
}
n>>=;
}
__int64 gong=(*((ans[][]*a)%m+(ans[][]*(a*a+b)%m)%m)%m)%m;
if(gong<) gong=m+gong;
printf("%I64d\n",gong);
}
return ;
}
HDUOJ--4565 So Easy!的更多相关文章
- HDU 4565 So Easy!(矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4565 题意: 题意: #include <iostream>#include <cs ...
- HDU 4565 So Easy!
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 数学(矩阵乘法):HDU 4565 So Easy!
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 4565 So Easy(矩阵解公式)
So Easy [题目链接]So Easy [题目类型]矩阵解公式 &题解: 感觉这种类型的题都是一个套路,这题和hdu 2256就几乎是一样的. 所以最后2Xn就是答案 [时间复杂度]\(O ...
- HDU 4565 So Easy!(公式化简+矩阵)
转载:http://www.klogk.com/posts/hdu4565/ 这里写的非常好,看看就知道了啊. 题意很easy.a,b,n都是正整数.求 Sn=⌈(a+b√)n⌉%m,(a−1)2&l ...
- HDU 4565 So Easy!(数学+矩阵快速幂)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the cei ...
- HDU 4565 So Easy! 数学 + 矩阵 + 整体思路化简
http://acm.hdu.edu.cn/showproblem.php?pid=4565 首先知道里面那个东西,是肯定有小数的,就是说小数部分是约不走的,(因为b限定了不是一个完全平方数). 因为 ...
- hdu 4565 So Easy! (共轭构造+矩阵快速幂)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 题目大意: 给出a,b,n,m,求出的值, 解题思路: 因为题目中出现了开根号,和向上取整后求 ...
- HDU 4565 So Easy! 广义斐波拉数 数论 (a+sqrt(b))^n%mod 模板
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 【构造共轭函数+矩阵快速幂】HDU 4565 So Easy! (2013 长沙赛区邀请赛)
[解题思路] 给一张神图,推理写的灰常明白了,关键是构造共轭函数,这一点实在是要有数学知识的理论基础,推出了递推式,接下来就是矩阵的快速幂了. 神图: 给个大神的链接:构造类斐波那契数列的矩阵快速幂 ...
随机推荐
- c# webBrowser下载图片
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { ...
- Latex初学者入门(三)-- 用BibTeX生成参考文献
昨boss要往期Elsevier 刊投文章,距上次排版貌似过了好久,生疏了不少,翻出以前的写的一些笔记再复习复习. 不过这次好多了,仅仅是改个格式,原始的文章已经用latex编写过了(个人感觉最头疼的 ...
- 500 OOPS: vsftpd: cannot locate user specified in 'chown_username':whoever
错误:500 OOPS: vsftpd: cannot locate user specified in 'chown_username':whoever解决方案:在vsftpd.conf中修改如下两 ...
- 如何读取抓取的wifi包内容
有密码的WIFI,WIFI的密码会生成一个临时会话密钥,这个临时会话密钥可以用来加密会话内容,也就是说.比如你在浏览网页,用有密码的WIFI,连接上以后,浏览的网页流量是加密了的,所以更安全.无密码的 ...
- struts 2中为什么抽象包不能包含action?
struts 2中为什么抽象包不能包含action?麻烦写详细点!
- 混沌数学之Baker模型
相关DEMO参见:混沌数学之离散点集图形DEMO 相关代码: // http://wenku.baidu.com/view/ac9b57ea172ded630b1cb65b.html class Ba ...
- CREATE DATABASE failed
由于环境需要, 故修改SQL Server 2012的默认的数据库的数据文件和日志文件的位置. 如下: 创建数据库, 遭遇报错. 错误信息: A file activation error occur ...
- Search in Rotated Sorted Array II leetcode java
题目: Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would ...
- WebSettings 文档 API 翻译 常用设置
. setDefaultFontSize(int size) Sets the default font size. The default is 16. setDefaultTextEncodin ...
- 搜狐视频Redis私有云平台CacheCloud
一.CacheCloud是做什么的 CacheCloud提供一个Redis云管理平台:实现多种类型(Redis Standalone.Redis Sentinel.Redis Cluster)自动部署 ...