HDU

给定的pp是素数,要求给定一个加法运算表和乘法运算表,使(m+n)^p=m^p+n^p(0m,n<p)(m+n)^p=m^p+n^p(0≤m,n<p)。
因为给定的p是素数,根据费马小定理得 (m+n)^(p1)1(mod p)
因此,(m+n)^pm+n (mod p)
同时,m^p+n^pm+n (mod p)
所以在模p意义下,(m+n)^p=m^p+n^p(0m,n<p) 恒成立,且加法运算与乘法运算封闭

#include<bits/stdc++.h>
using namespace std;
const int maxn =1e5+5;
typedef long long LL;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int p;
    int T; scanf("%d",&T);
    while(T--){
        scanf("%d",&p);
        for(int i=0;i<p;++i){
            for(int j=0;j<p;++j){
                printf("%d%c",(i+j)%p,j==p-1?'
':' ');
            }
        }
        for(int i=0;i<p;++i){
            for(int j=0;j<p;++j){
                printf("%d%c",(i*j%p),j==p-1?'
':' ');
            }       
        }
    }
    return 0;
View Code
原文地址:https://www.cnblogs.com/shuaihui520/p/9536655.html