HDOJ 4762 Cut the Cake (확률 + Java)
2923 단어 수론
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)
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/(m^(n-1)) nm Java
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner cin=new Scanner(System.in);
BigInteger a,b;
int n,m;
int cla;
cla=cin.nextInt();
while(cla-->0)
{
m=cin.nextInt();
n=cin.nextInt();
a=BigInteger.valueOf(n);
b=BigInteger.valueOf(1);
for(int i=1;i<n;i++)
{
b=b.multiply(BigInteger.valueOf(m));
}
BigInteger g=a.gcd(b);
System.out.println(a.divide(g)+"/"+b.divide(g));
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[HDU 5608] functionProblem Description There is a function f(x),which is defined on the natural numbers set N,satisfies the following eqaut...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.