Exponentiation

Time Limit: 1000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 6973    Accepted Submission(s): 1975

Problem 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

大数的题目使用Java就变得其简单无比。

主要就一句代码:

String ans = a.pow(b).stripTrailingZeros().toPlainString();

去零和转换为纯字符串输出。

这使用C++要数十行代码。

对照C++解法:http://blog.csdn.net/kenden23/article/details/23997827

相比之下。java就成了水题了。学不到什么东西。

import java.math.BigDecimal;
import java.util.*; public class Main
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
while (scan.hasNext())
{
BigDecimal a = scan.nextBigDecimal();
int b = scan.nextInt();
String ans = a.pow(b).stripTrailingZeros().toPlainString();
if (ans.startsWith("0")) ans = ans.substring(1);
System.out.println(ans);
}
scan.close();
}
}

HDU Exponentiation 1063 Java大数题解的更多相关文章

  1. hdu 1042 N! java大数及判断文件末尾

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submi ...

  2. poj1001 Exponentiation【java大数】

    Exponentiation Time Limit: 500MS   Memory Limit: 10000K Total Submissions: 183034   Accepted: 44062 ...

  3. [ACM_数学] 大菲波数 (hdu oj 1715 ,java 大数)

    大菲波数 Problem Description Fibonacci数列,定义如下:f(1)=f(2)=1f(n)=f(n-1)+f(n-2) n>=3.计算第n项Fibonacci数值.   ...

  4. hdu 4043 FXTZ II [ 概率 + Java大数]

    传送门 FXTZ II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. 【百度之星】【java大数+C++做法】hdu 6719 Strassen

    代码:递归搜索一下.java大数做法 import java.util.*; import java.math.*; import java.security.MessageDigest; publi ...

  6. 【Java】-BigInteger大数类的使用【超强Java大数模板 总结】

    Scanner cin = new Scanner(new BufferedInputStream(System.in)); 这样定义Scanner类的对象读入数据可能会快一些! 参考这个博客继续补充 ...

  7. 多校第五场 归并排序+暴力矩阵乘+模拟+java大数&amp;记忆化递归

    HDU 4911 Inversion 考点:归并排序 思路:这题呀比赛的时候忘了知道能够用归并排序算出逆序数,可是忘了归并排序的实质了.然后不会做-- 由于看到题上说是相邻的两个数才干交换的时候.感觉 ...

  8. Java 大数、高精度模板

    介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...

  9. hdu1133 Buy the Ticket (卡兰特数应用+java大数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1133 [题意] 电影票50块一张 有m个人手里正好有50块,n个人手里正好有100块,售票厅開始没有 ...

随机推荐

  1. java改变图片文件尺寸

    package test.common; import java.awt.Graphics; import java.awt.Image; import java.awt.image.Buffered ...

  2. 新浪IP归属地API

    之前用过腾讯的AIP,但是官方暂停这个服务了,新浪的API时间很久了,稳定性也很好,但愿能一劳永逸. ''' '''

  3. SMO要点总结

    SMO要点总结: SMO使用坐标上升的方法,求解SVM的最优解.和原始坐标上升方法的不同点在于: 1.       由于SVM的限制条件 ,所以不能只使用一个坐标,改为更新两个 2.       采用 ...

  4. aix lvm_lv_vg

    Aix扩展文件系统,添加新硬盘 Cfgmgr 重新扫描新硬盘 Lspv Chdev –l hdisk3 –a pv=yes Extendvg rootvg hdisk3 note 上面的报错解决 Sm ...

  5. poj1144Network(无向图割点数)

    题目请戳这里 题目大意:给一张无向图,求割点数量. 题目分析:tarjan算法求割点.关于无向图割点,这里说的很清楚了.直接建图跑一遍tarjan算法即可. 详情请见代码: #include < ...

  6. QT函数

    1 move 移动 2 resize 改变窗口大小 3 setNum 设置数字 4 setText 设置文本 5 setWindowTitle 设置窗口文本 6 show 弹出窗口 7 text 获取 ...

  7. 开发该选择Blocks还是Delegates(转)

    原文链接:http://blog.stablekernel.com/blocks-or-delegates/ By Joe Conway,CEO | Jul 11,2013 11:29:00 AM 有 ...

  8. jQuery学习笔记(一)——基础选择器、过滤选择器、表单选择器

    $()就是jQuery中的函数,它的功能是获得()中指定的标签元素.如演示样例中$("p")会得到一组P标签元素,当中"p"表示CSS中的标签选择器.$()中的 ...

  9. ASP.NET MVC 学习之路-3

    本文在于巩固基础 到这里不得不说ASP.NET MVC一个规则:惯例优先原则 ASP.NET会假定开发人员遵循特定的规则来构建自己的程序而不是使用配置文件 ASP.NET MVC文件夹结构也遵循惯例优 ...

  10. 《think in python》学习-6

    think in python 有返回函数 我们使用过的内置函数中,有一部分会返回结果,比如 math的 返回值 我们写一个有返回值的函数,计算给定半径的圆的面积,例如这个: def area(rad ...