UVA10843——Anne\'s game

Lily: “Chantarelle was part of my exotic phase.”

Buffy: “It’s nice. It’s a mushroom.”

Lily: “It is? That’s really embarrassing.”

Buffy: “Well, it’s an exotic mushroom, if that’s any comfort.”

Joss Whedon, "Anne".

A little girl whose name is Anne Spetring likes to play the following game. She draws a circle on

paper. Then she draws another one and connects it to the first cicrle by a line. Then she draws another

and connects it to one of the first two circles by a line. She continues this way until she has n circles

drawn and each one connected to one of the previously drawn circles. Her circles never intersect and

lines never cross. Finally, she numbers the circles from 1 to n in some random order.

How many different pictures can she draw that contain exactly n circles? Two pictures are different

if one of them has a line connecting circle number i to circle number j, and the other picture does not.

Input

The first line of input gives the number of cases, N. N test cases follow. Each one is a line containing

n (0 < n ≤ 100).

Output

For each test case, output one line containing ‘Case #x:’ followed by X, where X is the remainder

after dividing the answer by 2000000011.

Sample Input

3

1

2

3

Sample Output

Case #1: 1

Case #2: 1

Case #3: 3

 

题意:题目说画圈,实际上圈可以看成是点,然后就是求n个点,可以接连出多少种不同的生成树的问题了!

 

思路:Caylay定理,网上能找到证明,结果为nn-2次方,然后利用快速二分幂求模去求解(以前总结的 快速二分幂求模)。


 code:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
const int mod=2000000011;
int T,n;

ll big_mod(int a,int b) //关键实现函数,以前总结
{
ll ans=1,t=a;
while(b)
{
if(b&1) ans=ans*t%mod;
t=t*t%mod;
b>>=1;
}
return ans%mod;
}
int main()
{
scanf("%d",&T);
for (int ca=1;ca<=T;ca++)
{
int ans=1;
scanf("%d",&n);
if (n>1) ans=big_mod(n,n-2);
printf("Case #%d: %d\n",ca,ans);
}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值