题意:
给定素数p,定义p内封闭的加法和乘法,使得$(m+n)^p=m^p+n^p$
思路:
由费马小定理,p是素数,$a^{p-1}\equiv 1(mod\;p)$
所以$(m+n)^{p}\equiv (m+n)(mod\;p)$
$m^{p}\equiv m(mod\;p)$
$n^{p}\equiv n(mod\;p)$
所以在模意义下,有$(m+n)^p=m^p+n^p$
代码:
#include<iostream> #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<string> #include<stack> #include<queue> #include<deque> #include<set> #include<vector> #include<map> #include<functional> #define fst first #define sc second #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,root<<1 #define rson mid+1,r,root<<1|1 #define lc root<<1 #define rc root<<1|1 #define lowbit(x) ((x)&(-x)) using namespace std; typedef double db; typedef long double ldb; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> PI; typedef pair<ll,ll> PLL; const db eps = 1e-6; const int mod = 1e9+7; const int maxn = 2e5+2; const int maxm = 2e6+100; const int inf = 0x3f3f3f3f; const db pi = acos(-1.0); int main() { int T; scanf("%d", &T); while(T--){ ll n; scanf("%I64d", &n); for(ll i = 0; i < n; i++){ for(ll j = 0; j < n; j++){ printf("%I64d ", (ll)(i+j)%n); } printf("\n"); } for(ll i = 0; i < n; i++){ for(ll j = 0; j < n; j++){ printf("%I64d ", (ll)i*j%n); } printf("\n"); } } return 0; }
原文地址:https://www.cnblogs.com/wrjlinkkkkkk/p/9538508.html
时间: 2024-11-05 17:32:16