2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1243 2016

来源:互联网 发布:怎么下载淘宝网到桌面 编辑:程序博客网 时间:2024/04/27 20:51

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 n1  . 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 2016 if you either:

  1. find it hard to solve;

  2. or, solved all the other problems easily.

Input

The input contains at most40 sets. For each set:

The first line contains an integern (1n<10 100000  ).

The second line contains2 integersa 11 ,a 12  .

The third line contains2 integersa 21 ,a 22  .

(0a ij <7 ,(a 11 a 22 a 12 a 21 ) is not a multiple of7 )

Output

For each set, a2×2 matrix denotes the remainder ofA n  after division by7 .

Sample Input

21 11 220161 11 2

Sample Output

2 33 51 00 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 1000000007using 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;}


0 0