列表

详情


NC52812. 2016

描述

Given a matrix

find where .
As the result may be large,
you are going to find only the remainder after division by 7.

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

输入描述

The input contains at most 40 sets. For each set:
The first line contains an integer n ().
The second line contains 2 integers .
The third line contains 2 integers .
(, is not a multiple of 7)

输出描述

For each set, a  matrix denotes the remainder of  after division by 7.

示例1

输入:

2
1 1
1 2

输出:

2 3
3 5

示例2

输入:

2016
1 1
1 2

输出:

1 0
0 1

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++14(g++5.4) 解法, 执行用时: 8ms, 内存消耗: 616K, 提交时间: 2019-10-06 14:37:12

#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s;
	int a11,a12,a22,a21;
	while(cin>>s){
		int n=0;
		int len=s.size();
		for(int i=0;i<len;i++)
			n=(n*10+s[i]-'0')%2016;
		scanf("%d%d",&a11,&a12);
		scanf("%d%d",&a21,&a22);
		n--;
		if(n<0) n+=2016;
		int t11=a11,t12=a12,t21=a21,t22=a22;
		while(n--){
			int s11=a11,s12=a12,s21=a21,s22=a22;
			a11=(s11*t11+s12*t21)%7;
			a12=(s11*t12+s12*t22)%7;
			a21=(s21*t11+s22*t21)%7;
			a22=(s21*t12+s22*t22)%7;
		}
		printf("%d %d\n",a11,a12);
		printf("%d %d\n",a21,a22);
	} 
    return 0;
}

C++11(clang++ 3.9) 解法, 执行用时: 9ms, 内存消耗: 528K, 提交时间: 2020-02-25 21:53:13

#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	string s;
	int n=0,a11,a12,a21,a22,s11,s12,s21,s22,i,j;
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		n=n*10+s[i]-'0';
		n%=2016;
	}
	n+=2016;
	scanf("%d%d%d%d",&a11,&a12,&a21,&a22);
	s11=a11;
	s12=a12;
	s21=a21;
	s22=a22;
	for(i=0;i<n-1;i++)
	{
		int k11,k12,k21,k22;
		k11=a11*s11+a12*s21;
		k12=a11*s12+a12*s22;
		k21=a21*s11+a22*s21;
		k22=a21*s12+a22*s22;
		s11=k11%7;
		s12=k12%7;
		s21=k21%7;
		s22=k22%7;
	}
	printf("%d %d\n%d %d",s11,s12,s21,s22);
}

Python3(3.5.2) 解法, 执行用时: 103ms, 内存消耗: 9992K, 提交时间: 2019-10-06 13:50:47

import socket
import optparse
import math


n=int(input())
m=n%2016
a11,a12=map(int,input().split())
a21,a22=map(int,input().split())
L=[a11,a12,a21,a22]
E=[1,0,0,1]
R=L[:]
def mul(L):
    T = L[:]
    L[0]=(T[0]*a11+T[1]*a21)%7
    L[1]=(T[0]*a12+T[1]*a22)%7
    L[2]=(T[2]*a11+T[3]*a21)%7
    L[3]=(T[2]*a12+T[3]*a22)%7
if(m==0):
    L=E[:]
for i in range(m-1):
    mul(L)
print(L[0],L[1])
print(L[2],L[3])

上一题