Topic Links:
http://acm.hdu.edu.cn/showproblem.php?pid=4762
Test instructions
Divide a prototype cake into an M-fan, and then make n strawberries happen on one of them.
Analysis:
We take one from the first to have n choices, and then the rest of the n-1 strawberry in the range of its polar angle [0,360/m].
The probability of a 1/m,n-1 is 1/m^ (n-1);
So the total probability is n/m^ (n-1). Because 20^20 exceeds longlong, high precision is required
The code is as follows:
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--;}}}
Hdu4762cut the Cake (probability)