8月19号CCPC——Graph Of Zhuper(未解答)

roblem Description
We define Zhu(G) as the value of G.( G is labeled undirected graphs with n nodes( self-loop and multiple edge are not allowed ) ).

The method of calculating Zhu(G) is easy , if G has K connected components, then Zhu(G) = gcd(size1,size2,...,sizek)

* sizek is the number of vertexs in connected component k

Now, Shen wants to know ∑Zhu(G), can you help him?

Because the answer may be large, so you are only need to output the answer modulo P.
 

Input
The first line is an integer T(1≤T≤10) describe the number of test cases.

For each testcase, the first line contains two numbers n and P.

You can assume that 1≤n≤30000,100000000≤P≤1000000009

There are no more than 5 testcases with n≥10000.

It is guaranteed that P is a prime number.
 

Output
For the kth test case , first output "Case #k: " , then output an integer as answer in a single line.
 

Sample Input
3
1 1000000007
2 1000000007
3 1000000007
 

Sample Output
Case #1: 1
Case #2: 3
Case #3: 16


欢迎大神来提供思路和答案。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值