LINK:Just Shuffleios
比較慫羣論 由於沒怎麼學過 置換也是剛理解。c++
這道題是 已知一個置換\(A\)求一個置換P 兩個置換的關鍵爲\(P^k=A\)ide
且k是一個大質數.ui
作法是李指導教個人.spa
\(k\sqrt{A}=p\)即\(A^{\frac{1}{k}}=p\)code
設當前置換大小爲r 那麼有 \(A^r=I\)其中I爲單位置換.ip
\(A^{r+1}=A\)那麼有\(A^{ar+1}=A\) 原式等於\(A^{\frac{ar+1}{k}}=P\)get
那麼只須要隨便找個a知足\(k|ar+1\)便可。因爲k是大質數必定有解.string
等價於求\(ar+1=0(mod k)\) 解不定方程便可 最後能夠線性推出答案。it
code//#include<bits\stdc++.h> #include<iostream> #include<iomanip> #include<cstdio> #include<cstring> #include<string> #include<ctime> #include<cmath> #include<cctype> #include<cstdlib> #include<queue> #include<deque> #include<stack> #include<vector> #include<algorithm> #include<utility> #include<bitset> #include<set> #include<map> #define ll long long #define db double #define INF 10000000000000000ll #define ldb long double #define pb push_back #define put_(x) printf("%d ",x); #define get(x) x=read() #define gt(x) scanf("%d",&x) #define gi(x) scanf("%lf",&x) #define put(x) printf("%d\n",x) #define putl(x) printf("%lld\n",x) #define gc(a) scanf("%s",a+1) #define rep(p,n,i) for(RE int i=p;i<=n;++i) #define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]]) #define fep(n,p,i) for(RE int i=n;i>=p;--i) #define vep(p,n,i) for(RE int i=p;i<n;++i) #define pii pair<int,int> #define mk make_pair #define RE register #define P 1000000007 #define gf(x) scanf("%lf",&x) #define pf(x) ((x)*(x)) #define uint unsigned long long #define ui unsigned #define EPS 1e-4 #define sq sqrt #define S second #define F first #define mod 1000000007 #define V vector<int> #define l(x) t[x].l #define r(x) t[x].r #define sum(x) t[x].sum #define cnt(x) t[x].cnt using namespace std; char buf[1<<15],*fs,*ft; inline char getc() { return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++; } inline int read() { RE int x=0,f=1;RE char ch=getc(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();} return x*f; } const int MAXN=100010,maxn=40010; int n,k; int a[MAXN],vis[MAXN],b[MAXN]; vector<int>w; int xx,yy; inline void exgcd(int a,int b) { if(!b){xx=1;yy=0;return;} exgcd(b,a%b); int zz=xx;xx=yy;yy=zz-a/b*yy; } inline void calc(int a,int b,int c) { exgcd(a,b); yy=(yy%a+a)%a; } inline void solve() { calc(w.size(),k,-1); vep(0,w.size(),i)b[w[i]]=w[(i+yy)%w.size()]; } int main() { //freopen("1.in","r",stdin); get(n);get(k); rep(1,n,i)get(a[i]); rep(1,n,i) { if(!vis[i]) { w.clear(); int x=a[i]; while(!vis[x]) { vis[x]=1; w.pb(x); x=a[x]; } solve(); } } rep(1,n,i)put_(b[i]); return 0; }