hduoj4762(Java处理大数)
来源:互联网 发布:淘宝上质量好的外贸店 编辑:程序博客网 时间:2024/05/17 08:41
Cut the Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1368 Accepted Submission(s): 659
Problem Description
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
公式:n/m^n-1
import java.math.BigInteger;import java.util.Scanner;public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sca=new Scanner(System.in); int t=sca.nextInt(); while(t>0){ t--; BigInteger m=sca.nextBigInteger(); int n=sca.nextInt(); m=m.pow(n-1); int gc=m.gcd(BigInteger.valueOf(n)).intValue(); System.out.println(n/gc+"/"+m.divide(BigInteger.valueOf(gc))); } }}
- hduoj4762(Java处理大数)
- java 处理大数
- JAVA大数的处理
- java 处理大数
- JAVA 处理 大数 POJ1001
- Java中处理大数
- JAVA大数处理
- JAVA的大数处理
- Java大数处理
- Java大数处理
- JAVA之大数处理
- Java大数处理
- java处理大数类
- Java处理大数
- Java大数处理
- 用JAVA处理大数
- java大数处理类
- 大数处理 JAVA
- js的静态类
- mybatis sql 的一些问题 with。。。as。。。
- FTP操作类
- mybatis sql 映射文件问题
- eclipse出现真机不能安装程序
- hduoj4762(Java处理大数)
- 开源实时日志分析ELK平台部署
- 写表格格式的时候经常会多出一页空白页
- AIDL的使用步骤
- Nginx日志文件的切割
- 发布lib到mavenCenter&jcenter
- Eclipse安装Maven插件
- 电信号簿助手APP的官网优化方案
- 提升WordPress 打开速度全面解决方案