1430: Little Monkey Fights

Source: Internet
Author: User

1430: Little Monkey Fight Time limit:5 Sec Memory limit:162 MB
submit:335 solved:241
[Submit] [Status] Description at the beginning of the forest there are n strangers little monkeys, they often fight, but both sides of the fight must not be good friends. After each fight, both sides of the fight and their good friends will know each other and become good friends. After N-1 fights, all the little monkeys in the forest will be good friends. The question now is how many different fights there are in total. For example, when n=3, there are {1-2,1-3}{1-2,2-3}{1-3,1-2}{1-3,2-3}{2-3,1-2}{2-3,1-3} six different kinds of fight process. Input an integer n. Output line, number of scenarios mod 9999991. Sample Input4
Sample Output96

HINT

50% of Data n<=10^3.
100% of Data n<=10^6.

Source

Sum: ... This seems to me in addition to bzoj1000 the shortest bzoj program ... I first saw the "Little monkey Fight" the word, and then saw the "fight once after the two sides become friends", at first thought and look at the set, but when I saw how many kinds of play when I found that I think more ... Obviously, for N nodes of the spanning tree, the kind of n^ (N-2), because this problem seems to fight with the order to repeat the calculation, so again a n!/n, that is (N-1)!, so f (x) = (x-1)!*x^ (x-2) (Ah hehe witty I even fast power are lazy writing it?)
1 Constp=9999991;2 varI,j,k,m,n:longint;l:int64;3 begin4READLN (n); l:=1;5       fori:=1  toN-2  Dol:= (L*n)MoDp;6       forI:= (n1)Downto 1  Dol:= (L*i)MoDp;7 Writeln (l);8 End.

1430: Little Monkey Fights

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.