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

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

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;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/A852852852852/article/details/51720162
个人分类: 几何&&数论 c/c++
上一篇2016长城信息杯中国大学生程序设计竞赛中南邀请赛 xtu 1249 Rolling Variance
下一篇xtu 1264 Partial Sum 2017湘潭邀请赛E
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭