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 ...
随机推荐
- seller vue 编写接口请求【mock数据】
[build]-[webpack.dev.conf.js] 或 [build]-[dev-server.js] 在webpack.dev.conf.js中的写法 var appData = requi ...
- [js]js的表单验证onsubmit方法
http://uule.iteye.com/blog/2183622 表单验证类 <form class="form" method="post" id= ...
- JMeter TCP性能测试
jmeter是一款纯java的性能测试工具,跨平台运行方便.提供图形化界面设置.简单易用. 在性能测试方法论中,很典型的方法就是二八原则,量化业务需求. 二八原则:指80%的业务量在20%的时 ...
- Oracle如何查询当前的crs/has自启动状态
我们知道在某些停机测试场景,是需要人为禁用crs/has的自启动的,防止过程中主机反复重启对数据库集群造成影响. 使用crsctl disable/enable crs命令可以禁用/启用crs的自启动 ...
- 1.Spring对JDBC整合支持
1.Spring对JDBC整合支持 Spring对DAO提供哪些支持 1)Spring对DAO异常提供统一处理 2)Spring对DAO编写提供支持的抽象类 3)提高编程效率,减少DAO编码量 Spr ...
- vuex使用一
至于为什么使用vuex在这里就不过多的解释了,直接进入正题 1.vuex的安装 cnpm install vuex -S 2.然后在main.js中引入 import Vue from 'vue' i ...
- C++实现 safaBase64编码跟nonSafeBase64编码的转换
默认Base64编码的字符串,用于网络传输是不安全的,因为Base64编码使用的标准字典含有“+”,“/”. 规则如下: //nonSafeBase64 到 safeBase64'+' ------ ...
- (4)Python3笔记 之 流程控制
一.条件控制 # 语法规则 if 变量(或表达式): 语句块1 elif 变量(或表达式): 语句块2 else: 语句块3 #示例 score = 83 if score > 90: prin ...
- armv8 memory system
在armv8中,由于processor的预取,流水线, 以及多线程并行的执行方式,而且armv8-a中,使用的是一种weakly-ordered memory model, 不保证program or ...
- 强化学习---A3C
Asynchronous Advantage Actor-Critic (A3C) 在RL任务中,我们本质上最终要学习的是策略(Policy) value-based方法:间接方法,即通过学习值函数( ...