Exponentiation(高精度大数)
Exponentiation
Description
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 R^n. Leading zeros should be suppressed in the output. Insignificant trailing zeros must not be printed. Don't print the decimal point if the result is an integer.
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
Hint
If you don't know how to determine wheather encounted the end of input:
s is a string and n is an integer
//计算 n 的 x 次方
//显然,是个大数题,正好来练练java,格式要控制好。
import java.math.BigDecimal;
import java.util.Scanner;
import java.lang.String; /**
* Created by happy_code on 2017/6/6.
*/
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String s;
int n;
while (sc.hasNext())
{
s=sc.next();
n=sc.nextInt();
BigDecimal base = new BigDecimal(s);
BigDecimal res = new BigDecimal("");
for (int i=;i<n;i++){
res = res.multiply(base);
}
String ans = res.toPlainString(); boolean ok = false;
int k;
for (k =;k<ans.length();k++){
if (ans.charAt(k)=='.'){
ok = true;
break;
}
}
int e=ans.length()-;
if (ok){
while(ans.charAt(e)=='') e--;
if (ans.charAt(e)=='.') e--;
}
int i = ;
while(ans.charAt(i)=='') i++;
for (;i<=e;i++){
if (i==&&ans.charAt(i)==''){
continue;
}
System.out.print(ans.charAt(i));
}
System.out.println();
}
}
}
Exponentiation(高精度大数)的更多相关文章
- uva748 - Exponentiation 高精度小数的幂运算
uva748 - Exponentiation Exponentiation Problems involving the computation of exact values of very ...
- Exponentiation java大数
Exponentiation 大数a的n次幂,直到读到EOF(文件结尾)为止,其中忽略小数后面的0 1 import java.util.*; 2 import java.math.*; 3 impo ...
- hdu 1063 Exponentiation (高精度小数乘法)
//大数继续,额,要吐了. Problem Description Problems involving the computation of exact values of very large m ...
- POJ 1001 Exponentiation 无限大数的指数乘法 题解
POJ做的非常好,本题就是要求一个无限位大的指数乘法结果. 要求基础:无限大数位相乘 额外要求:处理特殊情况的能力 -- 关键是考这个能力了. 所以本题的用例特别重要,再聪明的人也会疏忽某些用例的. ...
- 1001. Exponentiation高精度运算总结
解题思路 这道题属于高精度乘法运算,要求输入一个实数R一个指数N,求实数R的N次方,由于R有5个数位,而N又特别大,因此用C++自带的数据类型放不下. 解题思路是通过数组储存每次乘积结果和底数的每一位 ...
- 【POJ 1001】Exponentiation (高精度乘法+快速幂)
BUPT2017 wintertraining(15) #6A 题意 求\(R^n\) ( 0.0 < R < 99.999 )(0 < n <= 25) 题解 将R用字符串读 ...
- Hdu 4762 网络赛 高精度大数模板+概率
注意题目中的这句话he put the strawberries on the cake randomly one by one,第一次选择草莓其实有N个可能,以某一个草莓为开头,然后顺序的随机摆放, ...
- POJ-1001 Exponentiation 高精度算法
题目链接:https://cn.vjudge.net/problem/POJ-1001 以前写过一个高精度乘法,但是没有小数点,实现起来也没什么难得, 现在把代码都般过来,等会把旧电脑弄一弄,暂时就不 ...
- PAT A1024题解——高精度大数相加模板
PAT:A1024 Palindromic Number A number that will be the same when it is written forwards or backwards ...
随机推荐
- 微信小程序 - 滑动显示地点信息(map)
演示效果如下: 资源如下 marker,png index.wxml <view class="map-container"> <map id="map ...
- ubuntu14.04 配置tomcat8
ubuntu下配置tomcat的过程事实上和windows是差点儿相同的,以下一起来看一下怎样在ubuntu14.04中配置tomcat. 1.下载tomcat 地址:http://tomcat.ap ...
- OpenERP7.0 忘记admin管理员密码解决办法
操作环境:linux Ubuntu12.10 OpenERP7.0 以下操作,请注意大小写 切换用户 root@ubuntu:~# su - postgres 查看数据库 postgres@ubun ...
- 用Volley-nullpointerexception
public Request(int method, String url, Response.ErrorListener listener) { mMethod = method; mUrl = u ...
- POJ 3221 Diamond Puzzle(BFS)
Description A diamond puzzle is played on a tessellated hexagon like the one shown in Figure 1 below ...
- LoadRunner中对图表的分析说明
LoadRunner中对图表的分析说明 (一)在Vusers(虚拟用户状态)中 1.Running Vusers(负载过程中的虚拟用户运行情况) 说明——系统形成负载的过程,随着时间的推移,虚拟用户数 ...
- Windows网络配置脚本
静态ip和动态ip切换 适用于:公司学校家庭的网络环境切换[请修改具体ip地址] ::ip for win7.bat::win8以上请用ipv4替换ip @echo off 设置为静态IP 设置为动态 ...
- URL中的#号
一.#的涵义 #代表网页中的一个位置.其右面的字符,就是该位置的标识符.比如, http://www.example.com/index.html#print 就代表网页index.html的prin ...
- rabbitmqctl 报错
RabbitMQ 安装成功后,cmd dos命令进入RabbitMQ的安装路径,如 E:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.10\sb ...
- Silverlight实例教程 - Validation数据验证基础属性和事件(转载)
Silverlight 4 Validation验证实例系列 Silverlight实例教程 - Validation数据验证开篇 Silverlight实例教程 - Validation数据验证基础 ...