HDU 4048 Zhuge Liang's stone sentinel maze

Source: Internet
Author: User
Zhuge Liang's stone sentinel maze

Time Limit: 10000/4000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 385 accepted submission (s): 106


Problem description
Zhuge Liang was a chancellor of the state of Shu Han during the Three Kingdoms Period of Chinese history. he is often recognized as the greatest and most accomplished strategist of his era. he was so smart that his name also means "wise man" in Chinese.

One of ZHUGE Liang's achievements in legend is the stone sentinel maze. it was an array of rocks and boulders built to defend against enemies. the formation was located on Yufu shore by the Yangtze River near present-day baidicheng, Chongqing, China, where supposed ruins of the array exist.

In Chapter 84 of the Historical Novel Romance of the Three Kingdoms, as Lu Xun neared baidicheng, he felt a strong enemy presence in the area and alerted his army to a possible ambush. he sent scouts ahead, who reported that the region was deserted should t for some scattered piles of rocks. the bewildered Lu Xun asked a local, who told him that Qi ("energy") started emerging from the area after zhug E Liang arranged the rocks there. lu Xun personally inspected the area and decided that the array was only a petty display of deception. hence, Lu Xun led a few horsemen with him into the maze, and as he was about to exit, there was a strong gust of wind. at that moment, dust storms overshadowed the sky and the rocks appeared to become valleys; mountainous piles of dirt emerged and the roar of thu Nder rocked the skies while the waves of the nearby Yangtze River sounded like the clashing of swords and beating of war drums...

After the research on the stone sentinel maze, scientists find some regulations. the rocks have m different kinds of weight (1 <= m <= 10,000 ). the weight of a rock is a positive integer not exceeding 10,000. there are N (3 <=n <= 100,000) rocks placed on a circle with equal spacing and the greatest common divisor of their weight is 1. they want to know in how many ways the rocks can be placed like that.

Notice:
1. Multiple rocks with the same weight can be placed on the circle.
2. If a solution will be the same as another one by rotation, these two solutions shoshould be consider as the same.
3. The answer may be quite large. You just need to calculate the remainder of the answer when divided by 10,007.

 

Inputthe input begins with a line containing an integer t, the number of test cases.
For each case, the first line begins with two integers --- the above mentioned M and N. then M lines follow, each containing a positive integer representing rock weight. it is guaranteed that these M integers are different.

 

Outputfor each case, output one integer in one line, representing the remainder of the number of ways when divided by 10,007.

 

Sample input22 3233 361015

 

Sample output22

 

Sourcethe 36th ACM/ICPC Asia Regional Beijing site -- online contest ,,, an) = 1; if the rotation is the same, it is regarded as one.

HDU 4048 Zhuge Liang's stone sentinel maze

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.