2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1243 2016
2016-06-20 13:44
288 查看
http://www.dengwenhuo.cn/?id=194
Given a2×2 matrix
A=(a 11 a 21 a 12 a 22 ),
findA n whereA 1 =A,A n =A×A n−1 .
As the result may be large, you are going to find only the remainder after division by7 .
Special Note: The problem is intended to be easy. Feel free to think why the problem is called
find it hard to solve;
or, solved all the other problems easily.
The input contains at most40 sets.
For each set:
The first line contains an integern (1≤n<10 100000 ).
The second line contains2 integersa 11 ,a 12 .
The third line contains2 integersa 21 ,a 22 .
(0≤a ij <7 ,(a 11 a 22 −a 12 a 21 ) is
not a multiple of7 )
For each set, a2×2 matrix
denotes the remainder ofA n after
division by7 .
Given a2×2 matrix
A=(a 11 a 21 a 12 a 22 ),
findA n whereA 1 =A,A n =A×A n−1 .
As the result may be large, you are going to find only the remainder after division by7 .
Special Note: The problem is intended to be easy. Feel free to think why the problem is called
2016if you either:
find it hard to solve;
or, solved all the other problems easily.
Input
The input contains at most40 sets.For each set:
The first line contains an integern (1≤n<10 100000 ).
The second line contains2 integersa 11 ,a 12 .
The third line contains2 integersa 21 ,a 22 .
(0≤a ij <7 ,(a 11 a 22 −a 12 a 21 ) is
not a multiple of7 )
Output
For each set, a2×2 matrixdenotes the remainder ofA n after
division by7 .
Sample Input
2 1 1 1 2 2016 1 1 1 2
Sample Output
2 3 3 5 1 0 0 1
#pragma comment(linker, "/STACK:102400000,102400000") #include<iostream> #include<cmath> #include<cstdio> #include<sstream> #include<cstdlib> #include<string> #include<string.h> #include<cstring> #include<algorithm> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<ctime> #include<bitset> #define eps 1e-6 #define INF 0x3f3f3f3f #define PI acos(-1.0) #define ll long long #define lson l,m,(rt<<1) #define rson m+1,r,(rt<<1)|1 #define M 1000000007 using namespace std; typedef struct { int m[2][2]; } Matrix; Matrix p; Matrix I= {1,0,0,1}; Matrix matrixmul(Matrix a,Matrix b) { int i,j,k; Matrix c; for(i=0; i<2; i++) for(j=0; j<2; j++) { c.m[i][j]=0; for(k=0; k<2; k++) c.m[i][j]+=(a.m[i][k]*b.m[k][j]); c.m[i][j]%=7; } return c; } Matrix quickpow(ll n) { Matrix m=p,b=I; while(n>=1) { if(n&1) b=matrixmul(b,m); n>>=1; m=matrixmul(m,m); } return b; } int main() { Matrix ans; int n; char a[100005]; while(~scanf("%s",a)) { scanf("%d %d %d %d",&p.m[0][0],&p.m[0][1],&p.m[1][0],&p.m[1][1]); n=0; for(int i=0; a[i]; i++) { n=(n*10+(a[i]-'0'))%2016; } ans=quickpow(n); printf("%d %d\n%d %d\n",ans.m[0][0],ans.m[0][1],ans.m[1][0],ans.m[1][1]); } return 0; }
相关文章推荐
- 深度学习2015年文章整理
- Android-扫二维码和生成二维码
- Zabbix 探索主机 “Discovery” 自动发现主机 详细图文教程
- 路径转换(转换成绝对路径)
- HttpClient请求网络数据
- liunx安装 memcached 及php拓展
- 【杭电oj】2064 - 汉诺塔III(递归,汉诺塔)
- Infer version 0.8.1安装(14.04 LTS)
- 【转】 jquery遍历json数组方法
- 剑指offer--打印1到最大的N位数字
- 2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1249 Rolling Variance
- iptables详解
- Deep Learning(深度学习)之(七)高维数据的机器学习
- 信号量sem 的用法
- 6/20 sprint3 看板和燃尽图的更新
- canvas模仿微信抢红包功能
- 2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1250 Super Fast Fourier Transform
- EF Attach时已存在的处理方式
- Android中常用的五种数据存储方式
- SQL SERVER 的时间转换。