HDU 5392 BC #51

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.