Problem Description
MMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly one of her friends HZ took some (N) strawberries which MMM likes very much to decorate the cake (of course they also eat strawberries, not just for decoration).
HZ is in charge of the decoration, and he thinks that it's not a big deal that he put the strawberries on the cake randomly one by one. After that, MMM would cut the cake into M pieces of sector with equal size and shape (the last one came to the party will
have no cake to eat), and choose one piece first. MMM wants to know the probability that she can get all N strawberries, can you help her? As the cake is so big, all strawberries on it could be treat as points.
Input
First line is the integer T, which means there are T cases.
For each case, two integers M, N indicate the number of her friends and the number of strawberry.
(2 < M, N <= 20, T <= 400)
For each case, two integers M, N indicate the number of her friends and the number of strawberry.
(2 < M, N <= 20, T <= 400)
Output
As the probability could be very small, you should output the probability in the form of a fraction in lowest terms. For each case, output the probability in a single line. Please see the sample for more details.
Sample Input
2 3 3 3 4
Sample Output
1/3 4/27
Problem Description
MMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly one of her friends HZ took some (N) strawberries which MMM likes very much to decorate the cake (of course they also eat strawberries, not just for decoration).
HZ is in charge of the decoration, and he thinks that it's not a big deal that he put the strawberries on the cake randomly one by one. After that, MMM would cut the cake into M pieces of sector with equal size and shape (the last one came to the party will
have no cake to eat), and choose one piece first. MMM wants to know the probability that she can get all N strawberries, can you help her? As the cake is so big, all strawberries on it could be treat as points.
Input
First line is the integer T, which means there are T cases.
For each case, two integers M, N indicate the number of her friends and the number of strawberry.
(2 < M, N <= 20, T <= 400)
For each case, two integers M, N indicate the number of her friends and the number of strawberry.
(2 < M, N <= 20, T <= 400)
Output
As the probability could be very small, you should output the probability in the form of a fraction in lowest terms. For each case, output the probability in a single line. Please see the sample for more details.
Sample Input
2 3 3 3 4
Sample Output
1/3 4/27
题意:M个小伙伴分蛋糕,有N个草莓随机分布在蛋糕上,你去把蛋糕平均切,并优先选择一块,问你能拿到所有草莓的概率。
思路:以最外面的一个草莓为第一刀为切的位置,这样一共有N种开刀位置,然后剩下N-1个草莓,每个的概率为1/M.如此以来概率为N / M ^ (N - 1); 要使用高精度,并且化简输出。
Java代码:
import java.io.*;
import java.util.*;
import java.math.*;
import java.math.BigInteger;
public class Main
{
public static void main(String[] args)
{
int T=0;
Scanner cin = new Scanner(System.in);
T=cin.nextInt();
while(T!=0)
{
T--;BigInteger m = cin.nextBigInteger();
int n = cin.nextInt();
// BigInteger cc = BigInteger.ONE;
BigInteger tmp = BigInteger.valueOf(n);
BigInteger ans = m.pow(n-1);
BigInteger g = ans.gcd(tmp);
System.out.println(tmp.divide(g)+"/"+ans.divide(g));
// BigInteger[] a = new BigInteger[n+10];
// BigInteger[] c = new BigInteger[n+10];
//
// for(int i=1;i<=n;i++)
// {
// a[i] = cin.nextBigInteger();
// }
//
// c[0] = BigInteger.ONE;
//
// BigInteger ans = BigInteger.ZERO;
//
}
}
}