is to seek the maximum common multiple, but to use the decomposition of the quality factor.
I wrote the WA to explode ....
#include <iostream> #include <stdio.h> #include <math.h> #include <algorithm>using namespace std; #define RD (X) scanf ("%d", &x) #define RD2 (x, y) scanf ("%d%d", &x,&y) #define LL Long Long int#define MAXN 3000005#define maxm 500010int t,n;int f[maxn],v[maxn],num[maxn];int Maxx (int a,int b) {return a>b?a:b;} int main () {rd (T); Long Long mod=3221225473; while (t--) {rd (n); for (int i=1;i<=n;i++) {rd (f[i]); v[i]=0; num[i]=0; } for (int i=1;i<=n;i++) {if (!v[i]) {int l=0; int k=i; while (!v[k]) {l++; V[k]=1; K=F[K]; }//the length of the Loop section for (int j=2;j*j<=l;j++)///mass factor decomposition {int nn=0; while (l%j==0) {nn++;l/=j;} Num[j]=maxx (NUM[J],NN); } if (l>1) num[L]=maxx (1,num[l]); }} ll Res=1; for (int i=2;i<=n;i++) {while (num[i]--) res= (res*i)%mod; } printf ("%i64d\n", res); } return 0;}
HDU 5392 BC #51