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

题意:切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大数)的更多相关文章

  1. java大数总结【转】

    java大数(2013长春网络赛)--hdu4762总结一下:1.java提交类要写Main.2.读取大数. Scanner read=new Scanner(System.in); BigInteg ...

  2. JAVA大数类

    JAVA大数类api http://man.ddvip.com/program/java_api_zh/java/math/BigInteger.html#method_summary 不仅仅只能查J ...

  3. java大数

    java大数还是很好用的! 基本加入: import java.math.BigInteger; import jave.math.BigDecimal; 分别是大数和大浮点数. 首先读入可以用: S ...

  4. JAVA大数运算

    java大数是个好东西,用起来方便,代码短. 代码如下: import java.util.*; import java.math.*; public class Main { public stat ...

  5. HDU5047Sawtooth(java大数)

    HDU5047Sawtooth(java大数) 题目链接 题目大意:在一个矩形内画n个"M".问如何画可以把这个矩形分成最多的区域. 给出这个区域的数目. 解题思路:最好的方式就是 ...

  6. ZOJ3477&JAVA大数类

    转:http://blog.csdn.net/sunkun2013/article/details/11822927 import java.util.*; import java.math.BigI ...

  7. 多校第五场 归并排序+暴力矩阵乘+模拟+java大数&amp;记忆化递归

    HDU 4911 Inversion 考点:归并排序 思路:这题呀比赛的时候忘了知道能够用归并排序算出逆序数,可是忘了归并排序的实质了.然后不会做-- 由于看到题上说是相邻的两个数才干交换的时候.感觉 ...

  8. 收藏的一段关于java大数运算的代码

    收藏的一段关于java大数运算的代码: package study_02.number; import java.math.BigDecimal; import java.math.BigIntege ...

  9. java大数判断相等

    java大数判断相等: 1.equals()方法2.compareTo()方法区别:2.00与2.0 equals()方法判断不等,compareTo()方法判断相等,科学的说法可以看java api ...

随机推荐

  1. 飘逸的python - 性能调优利器profile及其意义

    VIM 的作者Bram Moolenaar在一篇叫高效文本编辑器的7个习惯的ppt中有这么一段话. Three basic steps 1.    Detect inefficiency 2.    ...

  2. LVM(1)

    DM: DM: Device Mapper    逻辑设备        RAID, LVM2        DM: LVM2    快照    多路径

  3. hdu 5612 Baby Ming and Matrix games(dfs暴力)

    Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...

  4. LinQ to SQL 查询

    LINQ to SQL 是将对象关系映射到.NET框架中的一种实现.它可以将关系数据库映射为.NET Framework中的一些类. 然后,开发人员就可以通过使用 LINQ to SQL对数据库中的数 ...

  5. 认识Ant

    Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能.在本文中,主要让读者熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作. 一.            ...

  6. js记录用户行为浏览记录和停留时间(转)

    演示地址:http://weber.pub/demo/160902/test.html 测试源码下载:http://pan.baidu.com/s/1nvPKbSP 密码:r147 解决问题所使用的知 ...

  7. (3)选择元素——(5)为项目列表加样式(Styling list-item levels)

    Let's suppose that we want the top-level items, and only the top-level items, to be arranged horizon ...

  8. Android项目svn代码管理问题

    用svn控制版本,svn本身是不会识别哪些该传,哪些不该传,这就导致有些关于路径的东西(比如拓展jar的路径)也被上传了,而当别人下载后,那个路径对于这个人可能完全不存在,项目编译就会出问题.用ecl ...

  9. ASP.Net请求处理机制初步探索之旅 - Part 1 前奏(转)

        在读本文之前建议先阅读IIS架构:http://www.cnblogs.com/tiantianle/p/5079932.html     不管是ASP.Net WebForm还是ASP.Ne ...

  10. iOS 开发者证书总结

    iOS 证书分两种类型. 第一种为$99美元的,这种账号有个人和公司的区别,公司账号能创建多个子账号,但个人的不能.这种账号可以用来上传app store 第二种为¥299美元的,这种账号只能用于企业 ...