2018中国大学生程序设计竞赛 - 网络选拔赛 C Dream (构造)

版权声明:欢迎转载,请注明此博客地址。 https://blog.csdn.net/Ever_glow/article/details/82054464

Dream

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 268    Accepted Submission(s): 3
Special Judge

Problem Description

Freshmen frequently make an error in computing the power of a sum of real numbers, which usually origins from an incorrect equation (m+n)p=mp+np, where m,n,p are real numbers. Let's call it ``Beginner's Dream''.

For instance, (1+4)2=52=25, but 12+42=17≠25. Moreover, 9+16−−−−−√=25−−√=5, which does not equal 3+4=7. 

Fortunately, in some cases when p is a prime, the identity

(m+n)p=mp+np
holds true for every pair of non-negative integers m,n which are less than p, with appropriate definitions of addition and multiplication.
You are required to redefine the rules of addition and multiplication so as to make the beginner's dream realized.
Specifically, you need to create your custom addition and multiplication, so that when making calculation with your rules the equation (m+n)p=mp+np is a valid identity for all non-negative integers m,n less than p. Power is defined as

ap={1,ap−1⋅a,p=0p>0
Obviously there exists an extremely simple solution that makes all operation just produce zero. So an extra constraint should be satisfied that there exists an integer q(0<q<p) to make the set {qk|0<k<p,k∈Z} equal to {k|0<k<p,k∈Z}. What's more, the set of non-negative integers less than p ought to be closed under the operation of your definitions.

Hint
Hint for sample input and output:
From the table we get 0+1=1, and thus (0+1)2=12=1⋅1=1. On the other hand, 02=0⋅0=0, 12=1⋅1=1, 02+12=0+1=1.
They are the same.

Input

The first line of the input contains an positive integer T(T≤30) indicating the number of test cases.

For every case, there is only one line contains an integer p(p<210), described in the problem description above. p is guranteed to be a prime.

Output

For each test case, you should print 2p lines of p integers.

The j-th(1≤j≤p) integer of i-th(1≤i≤p) line denotes the value of (i−1)+(j−1). The j-th(1≤j≤p) integer of (p+i)-th(1≤i≤p) line denotes the value of (i−1)⋅(j−1).

Sample Input

1 2

Sample Output

0 1 1 0 0 0 0 1

可能这个题就是不懂题意吧,一直素数p,要求构造矩阵a[p*p],使其满足:(m+n)^p=m^p+n^p
a的含义:a[i][j] = (i-1) + (j-1),a[p+i][j] = (i-1) * (j-1)

然后我是找规律啊,还是放一下官方题解吧。
这里P是一个素数,由费马小定理,对于a属于Z
a^p \equiv a\ mod\ p

所以对于0\leq x,y<p

(x+y)^p\equiv x+y \equiv x^p+y^p\ mod\ p

于是只需要将加法与乘法定义为:

m+n:=(m+n)\ mod\ p

m\cdot n:=(m\cdot n)\ mod\ p

即可。至于集合相等的那个约束,验证一下可以发现是正确的。

代码实现:
 

/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
int main()
{
    ll t,p,i,j,k;
    sl(t);
    while(t--)
    {
        sl(p);
        //add
        for(i = 0;i < p;i++)
        {
            printf("%lld",i);
            for(j = 1;j < p;j++)
            {
                printf(" %lld",(i+j)%p);
            }
            puts("");
        }
        //mul
        for(i = 0;i < p;i++)
        {
            printf("0");
            for(j = 1;j < p;j++)
            {
                printf(" %lld",(i*j)%p);
            }
            puts("");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/Ever_glow/article/details/82054464