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. WPF最基本的4个引用

    Windowsbase Windows基本类库 PresentationCore wpf核心类库 PresentationFramework wpf框架 System.Axml 系统类库

  2. python高级编程之描述符与属性02

    # -*- coding: utf-8 -*- # python:2.x __author__ = 'Administrator' #元描述符 #特点是:使用宿主类的一个或者多个方法来执行一个任务,可 ...

  3. 文件读写IO

    摘要:本文主要总结了以下有关文件读写的IO,系统调用与库函数. 1.初级IO函数:close,creat,lseek,open,write 文件描述符是一个整型数 1.1close 1.2int cr ...

  4. java类加载器行为[笔记]

    1. Java虚拟机使用第一个类的第一件事情就是将该类的字节码装进来,装载类字节码的功能是由类装器完成的,类半遮器负责根据一个类的名称来定位和生成类的字节码数据后返回给Java虚拟机. 2. 类装载器 ...

  5. Docker网络管理-外部访问容器

    注意:这里使用的方法是端口映射,需要说明的是端口映射是在容器启动的时候才能完成端口映射的. 1,搭建1个web服务器,让外部机器访问. docker run -itd centos /bin/bash ...

  6. C#基于委托的带参数的消息传递设计

    需求场景 在对象A中注册消息,指定回调函数 在对象B中解释消息,调用对应的回调函数,附上对应的参数对象 定义 public delegate void MessengerDelegate(object ...

  7. Javascript进阶篇——( JavaScript内置对象---下)--Math对象---笔记整理

    Math对象使用 Math 的属性和方法: <script type="text/javascript"> var mypi=Math.PI; var myabs=Ma ...

  8. 关于uisliderview 监听停止滑动的状态

    今天遇到一个问题,做颜色控制的时候,通过slider 改变颜色的亮度.如果直接在slider 上绑定事件,则改变一次就需要向服务器发送一次请求.这种是显然不合理的. 所以使用了下面的解决方法 先将sl ...

  9. OpenCV——肤色检测

    一.RGB color space 检测代码如下: void SkinRGB(IplImage* src,IplImage* dst) { //RGB颜色空间 //均匀照明:R>95,G> ...

  10. YUI Array 之 indexOf(索引值|搜索)

    YUI原码 YUI indexOfYArray.indexOf = Lang._isNative(Native.indexOf) ? function (array, value, from) { r ...