UVA 10518 How Many Calls?
题意:一个递推式第n项%b是多少。
递推式:
构造矩阵:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std; long long MOD;
long long n; struct Matrix
{
long long A[][];
int R, C;
Matrix operator*(Matrix b);
}; Matrix X, Y, Z; Matrix Matrix::operator*(Matrix b)
{
Matrix c;
memset(c.A, , sizeof(c.A));
int i, j, k;
for (i = ; i <= R; i++)
for (j = ; j <= b.C; j++)
for (k = ; k <= C; k++)
c.A[i][j] = (c.A[i][j] + (A[i][k] * b.A[k][j]) % MOD) % MOD;
c.R = R; c.C = b.C;
return c;
} void init()
{
memset(X.A, , sizeof X.A);
memset(Y.A, , sizeof Y.A);
memset(Z.A, , sizeof Z.A); Z.R = ; Z.C = ;
Z.A[][] = Z.A[][] = Z.A[][] = ; X.R = ; X.C = ;
X.A[][] = ; X.A[][] = ; X.A[][] = ;
X.A[][] = ; X.A[][] = ; X.A[][] = ;
X.A[][] = ; X.A[][] = ; X.A[][] = ; Y.R =; Y.C = ;
for (int i = ; i <= ; i++) Y.A[i][i] = ;
} void work()
{
while (n)
{
if (n % == ) Y = Y*X;
n = n >> ;
X = X*X;
}
Z = Z*Y; printf("%lld\n", Z.A[][]);
} int main()
{
int Case = ;
while (~scanf("%lld%lld", &n, &MOD))
{
if (!n&&!MOD) break;
init();
printf("Case %d: %lld %lld ", Case++, n, MOD);
work();
}
return ;
}
UVA 10518 How Many Calls?的更多相关文章
- uva 10518 - How Many Calls?(矩阵快速幂)
题目链接:uva 10518 - How Many Calls? 公式f(n) = 2 * F(n) - 1, F(n)用矩阵快速幂求. #include <stdio.h> #inclu ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
- ACM--[kuangbin带你飞]--专题1-23
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- UVA 1456 六 Cellular Network
Cellular Network Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- UVA 1619 Feel Good(DP)
Bill is developing a new mathematical theory for human emotions. His recent investigations are dedic ...
- POJ 2796[UVA 1619] Feel Good
Feel Good Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 16786 Accepted: 4627 Case T ...
- uva live 6827 Galaxy collision
就是给出非常多点,要求分成两个集合,在同一个集合里的点要求随意两个之间的距离都大于5. 求一个集合.它的点数目是全部可能答案中最少的. 直接从随意一个点爆搜,把它范围内的点都丢到跟它不一样的集合里.不 ...
随机推荐
- 【转】Java 内部类种类及使用解析
Java 内部类种类及使用解析 内部类Inner Class 将相关的类组织在一起,从而降低了命名空间的混乱. 一个内部类可以定义在另一个类里,可以定义在函数里,甚至可以作为一个表达式的一部分. Ja ...
- android Button获取焦点
有时直接使用requestFocus()不能给button设置焦点,经网上查找得到如下结论: 先setFocus,再requestFocus. btn.setFocus ...
- PAT (Advanced Level) 1113. Integer Set Partition (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- Linux 下 git的使用
参考链接:http://www.liaoxuefeng.com 安装 安装步骤: ①先给操作系统装入git工具,以Linux为例: $ sudo apt-get install git ②去githu ...
- PAT1003
As an emergency rescue team leader of a city, you are given a special map of your country. 作为一个城市的紧急 ...
- ASP.NET中的Response
Response.BufferOutput=true.false 是否设置缓存 Response.Write("") 输出字符串 Response.IsClientConne ...
- 转 sqlplus执行sql报错:ORA-01756:
1.sqlplus执行sql报错:ORA-01756: quoted string not properly terminated 分类: 技术 在SQLPLUS中执行SQL文件时 ...
- FusionCharts使用问题及解决方法(四)-FusionCharts常见问题大全
在前3篇文章中,我们总结了FusionCharts图表的一些常见问题(FAQ)及解决方法,本文继续讨论FusionCharts使用者常见的一些复杂的报错及解决方法. 问题描述:使用FusionChar ...
- 花店橱窗(flower)
花店橱窗(flower) 题目描述 某花店现有f束花,每一束花的品种都不一样,同时至少有同样数量的花瓶,被按顺序摆成一行,花瓶的位置是固定的,从左到右按1到V顺序编号,V是花瓶的数目.花束可以移动,并 ...
- decimal 和 numeric (Transact-SQL)
decimal(18,0)18是定点精度,0是小数位数.decimal(a,b)a指定指定小数点左边和右边可以存储的十进制数字的最大个数,最大精度38.b指定小数点右边可以存储的十进制数字的最大个数. ...