2016CCPC 中南地区邀请赛 A 矩阵快速幂
A
A^n=A^(n%2016)%7;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
const int MOD = 1e9+;
#define LL long long
double const pi = acos(-);
// void fre() {
// freopen("in.txt","r",stdin);
// }
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// } int mod(string s){
int len;
int i;
int ans=;
len=s.length();
// cout<<s<<endl;
for(i=;i<len;i++)
ans=(ans*+s[i]-'')%;
return ans;
} struct matrix
{
int m[][];
}ans, base; matrix multi(matrix a, matrix b)
{
matrix tmp;
for(int i = ; i < ; ++i)
{
for(int j = ; j < ; ++j)
{
tmp.m[i][j] = ;
for(int k = ; k < ; ++k)
tmp.m[i][j] = (tmp.m[i][j] + a.m[i][k] * b.m[k][j]) % ;
}
}
return tmp;
} void fast_mod(int n)
{
int a,b,c,d;
scanf("%d%d%d%d",&a,&b,&c,&d);
base.m[][] =a;
base.m[][] =b;
base.m[][] =c;
base.m[][] =d;
ans.m[][] = ans.m[][] = ;
ans.m[][] = ans.m[][] = ;
if(n==){
printf("1 0\n");
printf("0 1\n");
return;
}
while(n)
{
if(n & )
{
ans = multi(ans, base);
}
base = multi(base, base);
n >>= ;
}
printf("%d %d\n",ans.m[][],ans.m[][]);
printf("%d %d\n",ans.m[][],ans.m[][]);
return;
} int main(){
// fre();
string s;
while(cin>>s){
int n;
n=mod(s);
// cout<<n<<endl;
fast_mod(n);
}
return ;
}
2016CCPC 中南地区邀请赛 A 矩阵快速幂的更多相关文章
- 2013长沙邀请赛A So Easy!(矩阵快速幂,共轭)
So Easy! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 徐州邀请赛 江苏 icpc I. T-shirt 矩阵快速幂
题目 题目描述 JSZKC is going to spend his vacation! His vacation has N days. Each day, he can choose a T-s ...
- 【构造共轭函数+矩阵快速幂】HDU 4565 So Easy! (2013 长沙赛区邀请赛)
[解题思路] 给一张神图,推理写的灰常明白了,关键是构造共轭函数,这一点实在是要有数学知识的理论基础,推出了递推式,接下来就是矩阵的快速幂了. 神图: 给个大神的链接:构造类斐波那契数列的矩阵快速幂 ...
- 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...
- 51nod 算法马拉松18 B 非010串 矩阵快速幂
非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...
- 51nod 1113 矩阵快速幂
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...
- 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】
还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...
- HDU5950(矩阵快速幂)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...
- 51nod 1126 矩阵快速幂 水
有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给出A,B和N,求f(n)的值. Input 输 ...
随机推荐
- 明晰三种常见存储技术:DAS、SAN和NAS
随着企业网络应用的时间和应用的数据量的加大,企业已经感觉到存储容量和性能落后与网络的应用发展需求,特别是流媒体企业,在这种应用条件下满足用户的存储需求的技术应用诞生,DAS.NAS和SAN三种存储技术 ...
- SNMP的工作原理&软件开发
SNMP(Simple Network Management Protocol,简单网络管理协议)首先是由IETF的研究小组为了解决Internet上的路由器管理问题而提出的.SNMP的设计原则是简单 ...
- WPF 位置转化和动画
位置转化 private void DrawScale() { double majorTickUnitValue = this.ScaleSweepLenth / this.MajorDivisio ...
- Side by Side Assembly介绍--manifest文件的使用
什么是Side-by-Side Assembly? Side-by-Side Assembly(建称SxS)是微软在Visual Studio 2005(Windows 2000?)中引入的技术,用来 ...
- PHP 怎么随机获取数组里面的值
注意array_rand随机返回的是KEY值的集合 <?php srand((float) microtime() * 10000000); $input = array("Neo&q ...
- Tarjan+模板
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #in ...
- HDU4611+数学
/* 找规律 题意:abs(i%A - i%B) 对i从0~N-1求和 从0~N-1一个一个算必TLE,着A,B两者差相同的部分合并起来算 */ #include<stdio.h> #in ...
- SPRING IN ACTION 第4版笔记-第九章Securing web applications-004-对密码加密passwordEncoder
一. 1.Focusing on the authentication query, you can see that user passwords are expected to be stored ...
- C++中的INL
inl文件介绍 inl文件是内联函数的源文件.内联函数通常在C++头文件中实现,但是当C++头文件中内联函数过多的情况下,我们想使头文件看起来简洁点,能不能像普通函数那样将内联函数声明和函数定义放在头 ...
- UVA548——Tree(中后序建树+DFS)
Tree You are to determine the value of the leaf node in a given binary tree that is the terminal nod ...