Codeforces 542C-a long and arduous process of solving problems

Source: Internet
Author: User

Although there are problems in the methods of solving the problem in the following part ...

But every time a resubmit is a meaningful patch.

I can see how many problems exist in the course of my problem ...

Now think, similar to the variable is not open int64, the procedure function forget to open int64. And there's a lot of problems in the middle.

  

C. idempotent functions

Some time ago Leonid have known About idempotent functions. idempotent function defined on a set {1, 2, ..., n }  is such function , that for any  the formula  G ( g ( x ) = g ( x )  holds.

Let ' s denote as  F ( K ) ( x )  the function  F  applied  K  times to the Value  x . More Formally,  F (1) ( x ) = F ( X ),   F ( K ) ( x ) = F ( F   ( K -1) ( x ))  for each  K > 1.

You are given some function.  Your task is to find minimum positive integer k such this functionf(k) (x) Is idempotent.

Input

The first line of the input there are a single integer n (1≤ n ≤200)-the size of Func tion f domain.

In the second line follow f(1), F(2), ..., f(n) (1≤ F( C22>i) ≤ n for each 1≤ in), the values of a function.

Just start the deal. I just started ignoring the data range, using a multiplier ... And then derive a series of bizarre questions.

First consider the existence of the ring in the data, then the answer in order to meet the needs of these numbers need to meet the size of all the rings divisible

And then for the other number, another consideration

Just started ignoring the data range, with two points ... And then finally found that seems to be not satisfied with the monotony of ...

Just started to think that as long as the absence of the ring must be a little closer to a certain direction

But the discovery forgot to consider the situation

So in fact, from small to large enumeration of the answer can be ...

Finally found that the whole process of revision is nothing more than two stages:

1) Change O (logn) multiplier to O (n) simulation

2) Change O (logn) 's binary answer to an O (N) enumeration answer

And then it's over ...

Can no longer despise the data range.

04./may

Codeforces 542C-a long and arduous process of solving problems

Related Article

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.