UVA - 748 Exponentiation
Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer systems.
This problem requires that you write a program to compute the exact value of Rn where R is a real number (0.0 < R < 99.999) and n is an integer such that 0 < n ≤ 25.
Input
The input will consist of a set of pairs of values for R and n. The R value will occupy columns 1 through 6, and the n value will be in columns 8 and 9.
Output
The output will consist of one line for each line of input giving the exact value of Rn. Leading zeros and insignificant trailing zeros should be suppressed in the output.
Sample Input
95.123 12
0.4321 20
5.1234 15
6.7592 9
98.999 10
1.0100 12
Sample Output
548815620517731830194541.899025343415715973535967221869852721
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
有趣的大数幂运算,如果直接用BigDecimal的话会错误,需要进行一点小小的处理。
import java.math.BigDecimal;
import java.util.Scanner; /**
*
* @author Asimple
* @date ${date}
*
*/ public class Main{ public static BigDecimal fun(BigDecimal num, int n) {
if( n==1 ) return num;
if( n%2==0 ) return fun(num,n/2).multiply(fun(num,n/2));
else return fun(num,n/2).multiply(fun(num,n/2)).multiply(num);
} static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
BigDecimal a;
int n;
while( sc.hasNext() ) {
a = sc.nextBigDecimal();
n = sc.nextInt();
String ans = "";
ans = fun(a,n).stripTrailingZeros().toPlainString();
if(ans.charAt(0) == '0') {
int i;
for(i=0; i<ans.length(); i++)
if(ans.charAt(i) != '0')
break;
System.out.println(ans.substring(i));
}
else System.out.println(ans);
}
}
}
UVA - 748 Exponentiation的更多相关文章
- uva 748 Exponentiation 浮点数乘方运算 高精度水题
输入的前六位数表示一个小数,然后输入一个数表示几次方.要求用高精度算出结果. 高精度水题,主要注意处理小数点,先在输入时把小数点提取出来并记录位置,用普通乘法计算出结果后由后向前计算位置添加小数点. ...
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- Volume 1. Big Number(uva)
如用到bign类参见大整数加减乘除模板 424 - Integer Inquiry #include <iostream> #include <string> #include ...
- 刘汝佳 算法竞赛-入门经典 第二部分 算法篇 第五章 2(Big Number)
这里的高精度都是要去掉前导0的, 第一题:424 - Integer Inquiry UVA:http://uva.onlinejudge.org/index.php?option=com_onlin ...
- uva748 - Exponentiation
import java.io.*; import java.text.*; import java.util.*; import java.math.*; public class Exponenti ...
- UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据
题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
随机推荐
- [OpenCV]代码整理
开发环境:Windows7, VS2010, OpenCV2.4.10 1.图像特征匹配 // AxFeatureExtract.cpp : 定义控制台应用程序的入口点. // #include &q ...
- Git的安装和配置用户名和密码
在Windows中进行安装.访问https://git-scm.com/,点击Downloads for Windows,我下载的是Git-2.16.2-64-bit.exe.都按照默认选项即可,其中 ...
- JsonResponse返回中文乱码问题
class Publish(APIView): def get(self, request): publish_list = models.Publish.objects.all() bs = MyS ...
- 如何比sketch和axure更方便地给原型做交互?
在快速的工作环境中,我们现在都希望在工作的各个环节中提高效率.有些产品设计师们做产品原型时,会感觉sketch或者axure添加交互的方式不够快捷.下面就提供一种解决方案. 使用工具:墨刀. 交互链接 ...
- Java Selenium - 元素定位(一)
一,单个元素对象定位 Webdriver通过findElement() , findElements()等方法调用By对象来定位和查询元素 , findElement()返回一个元素对象,否则抛出异常 ...
- gcc dynamic load library
Linux下一般都是直接在编译生成时挂接上链接库,运行时,把链接库放到系统环境里就可以了 但是windows出现带来了动态链接的概念,也就兴起了非windows世界的插件的概念的范潮 对应于windo ...
- redhat vim编辑器永久添加行号及搜索
设置行号: 跳转到home $ cd ~ 编辑.vimrc,没有的话自动创建 $ vim .vimrc 第一行加入: set nu :wq 保存退出,即可 如果想取消设置,同理删除set nu即可 v ...
- bootstrap ui
附加访问地址:http://www.bootcss.com/p/jquery-ui-bootstrap/
- LeetCode108.将有序数组转换为二叉搜索树
将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索树. 本题中,一个高度平衡二叉树是指一个二叉树每个节点 的左右两个子树的高度差的绝对值不超过 1. 示例: 给定有序数组: [-10,-3,0, ...
- kafka 单机配置
http://blog.csdn.net/jingshuigg/article/details/24439637 . su root : chown -R hadoop:hadoop version- ...