HDU4762 (Java large number)

Source: Internet
Author: 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 she 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 th EY 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 randoml Y one by one. After then, MMM would cut the cake into M pieces of sector with equal size and shape (the last one came to the party would There is no cake to eat), and choose one piece first. MMM wants to know the probability so she can get all N strawberries, can I help her? As the cake is so big and all strawberries on it could be treat as points.

Inputfirst line was the integer t, which means there is t cases.
For each case, a integers M, N indicate the number of her friends and the number of strawberry.
(2 < M, N <=, T <= 400)

Outputas the probability could is very small, you should output the probability in the form of a fraction in lowest terms. For each case, the output of the probability. Please see the sample for more details.

Sample Input23 33 4

Sample OUTPUT1/34/27 Test Instructions: cut m-block cake, to find the probability of n strawberries all on a piece of cake. Formula: n/(n-1 of M); Harvest: Understand the next large number of java. Simplification can be used with two numbers of least common multiple.
Importjava.math.*;ImportJava.util.*; Public classMain { Public Static voidMain (string[] args) {//TODO auto-generated Method StubScanner in =NewScanner (system.in); intt =In.nextint ();  while(t-->0) {BigInteger m=In.nextbiginteger (); intn =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 large number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.