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 矩阵快速幂的更多相关文章

  1. 2013长沙邀请赛A So Easy!(矩阵快速幂,共轭)

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

  2. 徐州邀请赛 江苏 icpc I. T-shirt 矩阵快速幂

    题目 题目描述 JSZKC is going to spend his vacation! His vacation has N days. Each day, he can choose a T-s ...

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

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

  4. 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)

    题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...

  5. 51nod 算法马拉松18 B 非010串 矩阵快速幂

    非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...

  6. 51nod 1113 矩阵快速幂

    题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...

  7. 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】

    还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...

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

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

随机推荐

  1. mybatis 中mapper 的namespace有什么用

    原文:http://zhidao.baidu.com/link?url=ovFuTn7-02s7Qd40BOnwHImuPxNg8tXJF3nrx1SSngNY5e0CaSP1E4C9E5J6Xv5f ...

  2. springMVC从上传的Excel文件中读取数据

    示例:导入客户文件(Excle文件) 一.编辑customer.xlsx 二.在spring的xml文件设置上传文件大小 <!-- 上传文件拦截,设置最大上传文件大小 10M=10*1024*1 ...

  3. ppshu

    全部书籍已经下载完毕! http://3cvpkfx4gdnkcduj.onion/ https://3cvpkfx4gdnkcduj.onion.cab/ https://3cvpkfx4gdnkc ...

  4. javascript div z-index, input tabindex属性说明

    <html> <body> <form> 用户名: <input type="text" tabindex="1" / ...

  5. codeforces #305 B Mike and Feet

    跟之前做过的51Nod的移数博弈是一样的QAQ 我们考虑每个数的贡献 定义其左边第一个比他小的数的位置为L 定义其右边第一个比他小的数的位置为R 这个可以用排序+链表 或者 单调队列 搞定 那么对于区 ...

  6. ArcGIS学习记录—union、merge及append的区别

    原文地址: ArcGIS问题:union.merge及append的主要区别[转] - Silent Dawn的日志 - 网易博客 http://gisman.blog.163.com/blog/st ...

  7. Android安全问题 抢先开机启动

    导读:我们以如何抢先开机启动为例,来说明接收无序广播的静态广播接收器的接收顺序 (注意,文本只是陈述结果,所以叫结果篇,之后的文章再给出源码分析) 首先先说一下android中的广播和广播接收器 广播 ...

  8. unite

    列出某个集合里的项目,比如file,buffer等 :United file——列出文件 :United buffer——列出buffer :United file_rec——递归列出文件 进入Uni ...

  9. Windows 7/8 创建WIFI热点

    问题描述:很多人(特别是中国的大学生)都拥有一台联网的笔记本电脑,而手机使用的却是电信运营商提供的限制数量和速度的GPRS. 很多人不敢想象:联网的笔记本电脑能够将其流量以WiFi的形式共享出来供其它 ...

  10. 大四实习准备6_android服务

    2015-5-9 1.服务是什么 android四大组件之一,有一些特点: 1)服务的运行不依赖于用户界面,即使程序被切换到后台.或者用户打开了另外一个应用程序,服务仍然能够保持正常运行.(当对应的程 ...