`
lilisalo
  • 浏览: 1110546 次
文章分类
社区版块
存档分类
最新评论

HDU/HDOJ 3923 2011 BJTU多校联合 波利亚原理

 
阅读更多

Invoker

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 122768/62768 K (Java/Others)
Total Submission(s): 515Accepted Submission(s): 163


Problem Description
On of Vance's favourite hero is Invoker, Kael. As many people knows Kael can control the elements and combine them to invoke a powerful skill. Vance like Kael very much so he changes the map to make Kael more powerful.

In his new map, Kael can control n kind of elements and he can put m elements equal-spacedly on a magic ring and combine them to invoke a new skill. But if a arrangement can change into another by rotate the magic ring or reverse the ring along the axis, they will invoke the same skill. Now give you n and m how many different skill can Kael invoke? As the number maybe too large, just output the answer mod 1000000007.

Input
The first line contains a single positive integer T( T <= 500 ), indicates the number of test cases.
For each test case: give you two positive integers n and m. ( 1 <= n, m <= 10000 )

Output
For each test case: output the case number as shown and then output the answer mod 1000000007 in a line. Look sample for more information.

Sample Input
2 3 4 1 2

Sample Output
Case #1: 21 Case #2: 1
Hint
For Case #1: we assume a,b,c are the 3 kinds of elements. Here are the 21 different arrangements to invoke the skills / aaaa / aaab / aaac / aabb / aabc / aacc / abab / / abac / abbb / abbc / abcb / abcc / acac / acbc / / accc / bbbb / bbbc / bbcc / bcbc / bccc / cccc /

Source


这个题是一个很裸露的波利亚定理的运用

但是最后取余要用逆元。

但是这个题比较巧妙,因为mod=1000000007,他是一个质数,于是要求某一个数的逆元的话直接mod-2次方,然后二分幂去模就行了

至于波利亚定理,我同样使用的POJ 2154以及POJ 2409的写法

我的代码:


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics