HDU1757 A Simple Math Problem 矩阵快速幂
A Simple Math Problem
Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4331    Accepted Submission(s): 2603
If x < 10 f(x) = x.
If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + …… + a9 * f(x-10);
And ai(0<=i<=9) can only be 0 or 1 .
Now, I will give a0 ~ a9 and two positive integers k and m ,and could you help Lele to caculate f(k)%m.
In each case, there will be two lines.
In the first line , there are two positive integers k and m. ( k<2*10^9 , m < 10^5 )
In the second line , there are ten integers represent a0 ~ a9.
#include<bits/stdc++.h>
#define N 10
#define mes(x) memset(x, 0, sizeof(x));
#define ll __int64
long long mod = 1e9+;
const int MAX = 0x7ffffff;
using namespace std;
struct mat{
ll a[N][N];
mat(){
memset(a, , sizeof(a));
}
mat operator *(mat b){
mat c;
for(int i=;i<N;i++)
for(int j=;j<N;j++)
for(int k=;k<N;k++)
c.a[i][j] = (c.a[i][j] + a[i][k]*b.a[k][j])%mod;
return c;
}
};
mat f(mat x,ll m){
mat t;
for(int i=;i<N;i++)
t.a[i][i] = ;
while(m){
if(m&) t = t*x;
x = x*x;
m >>= ;
}
return t;
}
int main()
{
ll k, i;
while(~scanf("%I64d%I64d", &k, &mod)){
if(k<){
printf("%I64d\n", k);
continue;
}
mat A, s;
for(i=;i<;i++)
s.a[][i] = -i;
for(i=;i<;i++)
scanf("%I64d", &A.a[i][]);
for(i=;i<;i++)
A.a[i][i+] = ;
s = s*f(A, k-);
printf("%I64d\n", s.a[][]);
} return ;
}
HDU1757 A Simple Math Problem 矩阵快速幂的更多相关文章
- HDU 1757 A Simple Math Problem (矩阵快速幂)
		
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
 - 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 ...
 - hdu 1757 A Simple Math Problem_矩阵快速幂
		
题意:略 简单的矩阵快速幂就行了 #include <iostream> #include <cstdio> #include <cstring> using na ...
 - 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 > ...
 - hdu------(1757)A Simple Math Problem(简单矩阵快速幂)
		
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
 - BestCoder Round #29——A--GTY's math problem(快速幂(对数法))、B--GTY's birthday gift(矩阵快速幂)
		
GTY's math problem Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
 - HDU 1757 A Simple Math Problem(矩阵)
		
A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...
 - A Simple Math Problem  矩阵打水题
		
A Simple Math Problem Lele now is thinking about a simple function f(x).If x < 10 f(x) = x.If x & ...
 - hdu1757 A Simple Math Problem
		
Problem Description Lele now is thinking about a simple function f(x).If x < 10 f(x) = x.If x > ...
 
随机推荐
- spark-submit常用参数
			
yarn模式默认启动2个executor,无论你有多少的worker节点 standalone模式每个worker一个executor,无法修改executor的数量 partition是RDD中的一 ...
 - js 去除空格
			
var MAX_PERIOD = $('#MAX_PERIOD').val(); // 借款的最大期限 MAX_PERIOD=Trim(MAX_PERIOD,"g"); //带 ...
 - Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的区别
			
Microsoft.Jet.OLEDB.4.0和Microsoft.ACE.OLEDB.12.0的区别 时间 2012-12-19 20:30:12 CSDN博客原文 http://blog.cs ...
 - rails创建项目,部署,测试流程(rails5.0+ruby2.3.1)
			
rails new test_app --skip-test-unit 不生成默认的test,稍后用rspeccd test_app 修改Gemfile(大部分为自动生成) source 'https ...
 - python添加tab键提示
			
新建一个tab.py脚本 #!/usr/bin/python import sys import readline import rlcompleter import atexit import os ...
 - [OrangePi] Installation on SD Card
			
Download any of the available images (xz archive) from Mega or GoogleDrive Download scriptbin_kernel ...
 - linux系统中grub配置文件
			
安装了Windows和Linux时肯定要通过GRUB进行引导,GRUB引导器的主配置文件路径/boot/grub/grub.conf(也可能是/boot/grub2/grub.conf),以#号开头的 ...
 - div内的img下出现几像素的空白间距解决办法
			
现象描述: 解决方法: 1.设父元素的font-size:0; 2.设img为display:block; 3.设img为vertical-align:middle;
 - Job类
			
当我们在写MapReduce程序的时候,通常,在main函数里,我们会像下面这样做.建立一个Job对象,设置它的JobName,然后配置输入输出路径,设置我们的Mapper类和Reducer类,设置I ...
 - equals和==
			
在初学Java时,可能会经常碰到下面的代码: 1 String str1 = new String("hello"); 2 String str2 = new String(&qu ...