2015
09-17

Cut the Cake

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.

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)

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)

2
3 3
3 4

1/3
4/27

http://acm.hdu.edu.cn/showproblem.php?pid=4762

//package fuck;

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
static BigInteger gcd(BigInteger a,BigInteger b){
if(!b.equals(BigInteger.ZERO)) return gcd(b,a.mod(b));
return a;
}
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
int t =  cin.nextInt();
while(t>0){
int m = cin.nextInt();
int n = cin.nextInt();
BigInteger N = BigInteger.valueOf(n);
BigInteger M = BigInteger.valueOf(m).pow(n-1);
BigInteger tmp = gcd(N,M);
System.out.println(N.divide(tmp)+"/"+M.divide(tmp));
t--;
}
}
}