HDU-5392 Infoplane in Tina town

Source: Internet
Author: User

The main idea: give a sequence, the transformation can return to the original position several times. For example 1 3 2, 3 is not in the original position, changed to 3 position, the number of changes to 2, the number of +1. Get 2.

Problem-solving ideas: the practice is to decompose the cycle length. Then ask for the least common multiple. But can not directly use LCM to seek least common multiple. We can consider the decomposition of prime numbers to seek, that is, the common mass factor multiplied by the mass factor of each number itself.

#include <cctype>#include <cstdio>#include <algorithm>using namespace STD;Const Long LongMOD =3221225473;Const intMAXN =3000010;intA[MAXN], REC[MAXN];namespaceIO {Const Static intMAXN = $<< -;Static CharBUF[MAXN], *pbuf = buf, *end;voidInit () {intc = fread (buf,1, MAXN, stdin);    End = buf + C; }int&readint () {Static intAns Ans =0; while(Pbuf! = End &&!)IsDigit(*PBUF)) Pbuf + +; while(Pbuf! = End &&IsDigit(*PBUF)) {ans = ans *Ten+ *pbuf-' 0 ';        Pbuf + +; }returnAns }}intMain () {io::init ();intT T = Io::readint (); while(t--) {intN n = io::readint (); for(inti =1; I <= N; i++) A[i] = Io::readint ();intCNT =0; for(inti =1; I <= N; i++) {intpos = i, TMP =0, Next; while(A[pos])                {next = A[pos]; A[pos] =0;                pos = next;            tmp++; }if(TMP! =0) rec[cnt++] = tmp; }Long LongAns =1; for(inti =0; I < CNT; i++) {intTMP = Rec[i]; for(intj =2; J * J <= tmp; J + +) {intnum =0; while(tmp% J = =0) {tmp/= J;                num++;            } A[j] = max (a[j], num); }if(tmp >1) a[tmp] = max (1, A[tmp]); } for(inti =2; I <= N; i++) while(a[i]--) ans = (ans * i)% MOD;printf("%lld\n", ans); }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU-5392 Infoplane in Tina town

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.