hdoj 4762 Cut the Cake
题意很简单就不说了。
解题的关键就是这个公式
answer=n/(m^(n-1));
要用到大数的乘法。然后java水过。
import java.util.*;
import java.math.*; public class Main {
public static BigInteger gcd (BigInteger a, BigInteger b) {
if (a.mod(b).equals(BigInteger.valueOf(0)))
return b;
return gcd(b, a.mod(b));
}
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int t = cin.nextInt();
BigInteger a, b, c;
int n, m;
while (t--!= 0) {
m = cin.nextInt();
n = cin.nextInt();
a = BigInteger.valueOf(1);
for (int i = 1; i < n; i++)
a = a.multiply(BigInteger.valueOf(m));
b = BigInteger.valueOf(n);
c = gcd(a, b);
System.out.println(b.divide(c) + "/" + a.divide(c));
}
cin.close();
}
}
hdoj 4762 Cut the Cake的更多相关文章
- HDU 4762 Cut the Cake(公式)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4762 Cut the Cake (2013长春网络赛1004题,公式题)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4762 Cut the Cake(高精度)
Cut the Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- HDU 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:将n个草莓随机放在蛋糕上,草莓被看做是点,然后将蛋糕平均切成m份,求所有草莓在同一块蛋 ...
- hdu 4762 Cut the Cake概率公式
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题目大意:一个圆形蛋糕,现在要分成M个相同的扇形,有n个草莓,求n个草莓都在同一个扇形上的概率. ...
- 2013长春网赛1004 hdu 4762 Cut the Cake
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4762 题意:有个蛋糕,切成m块,将n个草莓放在上面,问所有的草莓放在同一块蛋糕上面的概率是多少.2 & ...
- hdu 4762 Cut the Cake (大数乘法)
猜公式: ans=n/m^(n-1) #include<stdio.h> #include<string.h> struct BigNum { ]; int len; }; i ...
- Cut the Cake(大数相乘)
MMM got a big big big cake, and invited all her M friends to eat the cake together. Surprisingly o ...
- HDU 4328 Cut the cake
Cut the cake Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
随机推荐
- 系统学习 Java IO (七)----字节数组流 ByteArrayInputStream/ByteArrayOutputStream
目录:系统学习 Java IO---- 目录,概览 ByteArrayInputStream 如果数据存储在数组中,ByteArrayInputStream 可以很方便读取,它可以返回 InputSt ...
- Redis 安装和配置(一)
一. mac下redis的安装 1. 官网http://redis.io/ 下载最新的稳定版本,这里是3.2.0 2. sudo mv 到 /usr/local/ 3. sudo tar -zxf r ...
- 汇编入门二 一些概念与PC组件
1.内存:想让CPU工作,必须提供指令与数据,而指令和数据存在于内存中. 2.指令和数据:有点抽象,上书(汇编语言 第二版): 3.存储单元:存储器(内存)被划分为多个存储单元,内个存储单元从0开始顺 ...
- ZTree简单粗暴快速使用
是什么:功能强大的树形插件 tip:查资料时痛苦的地方,自我改进 1.没有注明版本:版本不对应导致配置完成后各种无端的错误,特别难查找,运气好能找到英文的解答 2.没有写明配置文件,或者不指明配置文件 ...
- nginx实现最简单的直播
系统环境 [root@yunwei-test live]# cat /etc/redhat-release CentOS Linux release (Core) [root@yunwei-test ...
- 微服务-springboot+websocket在线聊天室
一.引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- CentOS 常用命令合集
tail -f ../logs/catalina.out 在Tomcat中的bin目录下查看Tomcat日志 ps -ef|grep java 查看Tomcat服 ...
- JDK1.8之ConcurrentHashMap
目录 简介 JDK1.7 JDK1.8 重要属性 Node类 ForwardingNode类 原子操作和Unsafe类 重要方法 初始化表操作(initTable) 插入键值对(put和putVal) ...
- Codeforces Gym101170J:Jupiter Orbiter(最大流)
题目链接 题意 有n次事件,q个队列,s个传感器.每个传感器接到一个队列,每个队列有一个容量. 接下来执行n次事件,每次事件都会有一个最大发送数据量d.和s个数据a,代表这次给每个s填入a的数据量. ...
- Appium+python自动化(十七)- 你难道猴哥失散多年的混血弟弟 - Monkey简介之开山篇(超详解)
简介 今天由宏哥给小伙伴们来介绍猴哥的混血弟弟=Monkey.Monkey 是Android SDK提供的一个命令行工具, 可以简单,方便地运行在任何版本的Android模拟器和实体设备上. Monk ...