So Easy!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1729    Accepted Submission(s): 556

Problem Description
  A sequence Sn is defined as:

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! 
 
Input
  There are several test cases, each test case in one line contains four positive integers: a, b, n, m. Where 0< a, m < 215, (a-1)2< b < a2, 0 < b, n < 231.The input will finish with the end of file.
 
Output
  For each the case, output an integer Sn.
 
Sample Input
2 3 1 2013 2 3 2 2013 2 2 1 2013
 
Sample Output
4 14 4
 
Source
 
 
此题的思路在于这儿....看图...
 
 /*快速矩@ 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!的更多相关文章

  1. HDU 4565 So Easy!(矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4565 题意: 题意: #include <iostream>#include <cs ...

  2. HDU 4565 So Easy!

    So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  3. 数学(矩阵乘法):HDU 4565 So Easy!

    So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. HDU 4565 So Easy(矩阵解公式)

    So Easy [题目链接]So Easy [题目类型]矩阵解公式 &题解: 感觉这种类型的题都是一个套路,这题和hdu 2256就几乎是一样的. 所以最后2Xn就是答案 [时间复杂度]\(O ...

  5. HDU 4565 So Easy!(公式化简+矩阵)

    转载:http://www.klogk.com/posts/hdu4565/ 这里写的非常好,看看就知道了啊. 题意很easy.a,b,n都是正整数.求 Sn=⌈(a+b√)n⌉%m,(a−1)2&l ...

  6. 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 ...

  7. HDU 4565 So Easy! 数学 + 矩阵 + 整体思路化简

    http://acm.hdu.edu.cn/showproblem.php?pid=4565 首先知道里面那个东西,是肯定有小数的,就是说小数部分是约不走的,(因为b限定了不是一个完全平方数). 因为 ...

  8. hdu 4565 So Easy! (共轭构造+矩阵快速幂)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4565 题目大意: 给出a,b,n,m,求出的值, 解题思路: 因为题目中出现了开根号,和向上取整后求 ...

  9. 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 ...

  10. 【构造共轭函数+矩阵快速幂】HDU 4565 So Easy! (2013 长沙赛区邀请赛)

    [解题思路] 给一张神图,推理写的灰常明白了,关键是构造共轭函数,这一点实在是要有数学知识的理论基础,推出了递推式,接下来就是矩阵的快速幂了. 神图: 给个大神的链接:构造类斐波那契数列的矩阵快速幂 ...

随机推荐

  1. Unity3d-Particle System系统的学习(三)

    这节课我们来实战下上几节讲的几乎所有Particle System用到的参数. 我们今天制作下图所示的粒子: 类似于带有光晕的魔法球.用到的材质也就是上节课用到的材质贴图. http://pan.ba ...

  2. 用emoji表情包来可视化北京市历史天气状况!

    用emoji表情包来可视化北京市历史天气状况!   最近有了一个突如其来的想法,主要是看到了R社区有大神做了emoji表情包,并已经打通了ggplot的链接,所以想用ggplot结合emoji表情做一 ...

  3. 基于CXF框架下的SOAP Webservice服务端接口开发

    最近对webservice 进行入门学习,网上也是找了很多的学习资料.总得感觉就是这了解点,那了解点.感觉不够系统,不够容易入门.差不多断断续续看了一个星期了,今天小有成果,把客户端,服务端都搞定了. ...

  4. 如何利用启明星Portal门户系统的Page模块构建工作流表单

    启明星门户网站的Pages模块支持构建自定义表单系统.这使得对于使用表单收集用户数据的需求来说非常有用. 本文介绍如何构建一个简单的“出差系统”. 1.在页面里增加Pages模块,建立人事部部门,然后 ...

  5. [leetcode]Construct Binary Tree from Preorder and Inorder Traversal @ Python

    原题地址:http://oj.leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 题意:根 ...

  6. Metronic V1.5.2 Responsive Admin Dashboard Template build with Twitter Bootstrap 3.0

    Template Name: Metronic - Responsive Admin Dashboard Template build with Twitter Bootstrap 3.0 Versi ...

  7. Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci

      Error:(1, 0) The android gradle plugin version 3.0.0-alpha1 is too old, please update to the lates ...

  8. 部署项目Nginx+Tornado+Supervisor

    http://www.jianshu.com/p/9bebb99368ea Tornado Tornado 和现在的主流 Web 服务器框架(包括大多数 Python 的框架)有着明显的区别:它是非阻 ...

  9. Linux - 系统路径加入命令

    系统路径加入命令 本文地址: http://blog.csdn.net/caroline_wendy 1. 在根文件夹建立bin文件夹: $mkdir bin 2. 改动".bash_pro ...

  10. IE11下javascript报堆栈溢出问题的解决

    在IE11浏览器下,使用日期函数里面的toLocaleDateString()会报堆栈溢出 不知道是不是跟我的其他相关代码有关,还是就是这个toLocaleDateString()在IE11确实不太一 ...