HDU4762(JAVA大數)

來源:互聯網
上載者:User

標籤:

Cut the Cake

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1102    Accepted Submission(s): 540


Problem DescriptionMMM 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. 

 

InputFirst 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) 

 

OutputAs 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 Input23 33 4 

 

Sample Output1/34/27題意:切M塊蛋糕,求N個草莓全部在一塊蛋糕上的機率。公式:n/(m的n-1次方);收穫:瞭解了下JAVA大數。化簡可以用兩個數的最小公倍數。
import java.math.*;import java.util.*;public class Main {    public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner in = new Scanner(System.in);        int t = in.nextInt();        while(t-->0)        {            BigInteger m = in.nextBigInteger();            int n = in.nextInt();            m=m.pow(n-1);             BigInteger b=BigInteger.valueOf(n);            BigInteger a;            a = m.gcd(b);            BigInteger c = m.divide(a);            BigInteger c2 = b.divide(a);            System.out.println(c2 + "/" + c);        }    }}

 

HDU4762(JAVA大數)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.