题意:
题意很简单,不多说了。

思路:

|f(10) |       |a0 a1 a2 ...a8 a9|    |f(9)|
| f(9)  |       | 1   0   0 ... 0    0 |    |f(8)|
| .....  |   =  | ..    ...    ...   ...    |     | ..   |
| f(2) |        | 0   0   0 ... 0    0|     |f(1)|
| f(1) |   | 0   0   0 ... 1    0|     |f(0)|

为自己留个模板。

 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = + ; int n,m; struct Matrix
{
int mat[][];
Matrix operator *(Matrix a)
{
Matrix c;
for(int i=;i<;i++)
{
for(int j=;j<;j++)
{
c.mat[i][j]=;
for(int k=;k<;k++)
{
c.mat[i][j]+=(mat[i][k]*a.mat[k][j])%m;
c.mat[i][j]%=m;
}
}
}
return c;
}
}; Matrix base, ans; void init()
{
for(int i=;i<;i++)
for(int j=;j<;j++)
{
if(i==j) ans.mat[i][j]=;
else ans.mat[i][j]=;
if(i-==j) base.mat[i][j]=;
else base.mat[i][j]=;
}
} void pow(int n)
{
while(n)
{
if(n&) ans=ans*base;
base=base*base;
n>>=;
}
} int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%d%d",&n,&m))
{
init();
for(int i=;i<;i++) scanf("%d",&base.mat[][i]);
if(n<) {printf("%d\n",n%m);continue;}
pow(n-);
int sum=;
for(int i=;i<;i++) sum=(sum+ans.mat[][i]*(-i))%m;
printf("%d\n",sum);
}
return ;
}

HDU 1757 A Simple Math Problem(矩阵快速幂模板)的更多相关文章

  1. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  2. hdu 1757 A Simple Math Problem_矩阵快速幂

    题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using na ...

  3. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  4. HDU1757 A Simple Math Problem 矩阵快速幂

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. A Simple Math Problem(矩阵快速幂)----------------------蓝桥备战系列

    Lele now is thinking about a simple function f(x).  If x < 10 f(x) = x.  If x >= 10 f(x) = a0 ...

  6. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  7. hdu-1757 A Simple Math Problem---矩阵快速幂模板题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1757 题目大意: 求递推式第k项模m If x < 10 f(x) = x.If x > ...

  8. HDU 1757 A Simple Math Problem(矩阵快速幂)

    题目链接 题意 :给你m和k, 让你求f(k)%m.如果k<10,f(k) = k,否则 f(k) = a0 * f(k-1) + a1 * f(k-2) + a2 * f(k-3) + …… ...

  9. hdu 1757 A Simple Math Problem (矩阵快速幂)

    Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 ...

  10. hdu 1757 A Simple Math Problem (矩阵快速幂,简单)

    题目 也是和LightOJ 1096 和LightOJ 1065 差不多的简单题目. #include<stdio.h> #include<string.h> #include ...

随机推荐

  1. Celery配置Redis数据库保存Return结果状态

    使用windows版本 1.于GitHUB下载https://github.com/ServiceStack/redis-windows Window版本,到路径: 2. 运行路径下:D:\redis ...

  2. 更新Newtonsoft.Json后报异常,未能加载文件或程序集“Newtonsoft.Json

    未能加载文件或程序集“Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed”或它的某一个 ...

  3. HTML5-CSS3-JavaScript(2)

    我们就从HTML5的基础总结起.希望可以提高自身的基础. HTML5 新增的通用属性 1. contentEditable 属性 HTML5 为大部分HTML元素都增加了contentEditable ...

  4. [py]py常用模块小结

    - python md5校验: https://blog.csdn.net/linda1000/article/details/17581035 import hashlib hashlib.md5( ...

  5. NLP总览

    一.自然语言处理概述 1)自然语言处理:利用计算机为工具,对书面实行或者口头形式进行各种各样的处理和加工的技术,是研究人与人交际中以及人与计算机交际中的演员问题的一门学科,是人工智能的主要内容. 2) ...

  6. Struts2-综合项目

    综合项目:视频后台管理系统 开发环境:Tomcat6(服务器)+jdk6(windows操作系统) 使用技术:struts2(后台)+jsp(前台显示)+ajax(信息传递)+json(服务器响应前台 ...

  7. Sizzle源码分析 (一)

    Sizzle 源码分析 (一) 2.1 稳定 版本 Sizzle 选择器引擎博大精深,下面开始阅读它的源代码,并从中做出标记 .先从入口开始,之后慢慢切入 . 入口函数 Sizzle () 源码 19 ...

  8. 缓存(图像 IO 14.2)

    缓存 如果有很多张图片要显示,最好不要提前把所有都加载进来,而是应该当移出屏幕之后立刻销毁.通过选择性的缓存,你就可以避免来回滚动时图片重复性的加载了. 缓存其实很简单:就是存储昂贵计算后的结果(或者 ...

  9. 2018-2019-2 20165209 《网络对抗技术》Exp5:MSF基础应用

    2018-2019-2 20165209 <网络对抗技术>Exp5:MSF基础应用 目录 一.基础问题回答和实验内容 二.攻击实例 主动攻击的实践 ms08_067 payload/gen ...

  10. 数据在千万级别上进行全文检索有哪些技术?强大的大数据全文索引解决方案-ClouderaSearch

    数据在千万级别上进行全文检索有哪些技术?强大的大数据全文索引解决方案-ClouderaSearch1.lucene (solr, elasticsearch 都是基于它) 2.sphinx3.elas ...