Exponentiation

Time Limit: 2000/500 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9107    Accepted Submission(s): 2654

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
 
Source
题意计算一个浮点数的多少次幂。
代码:
第一次用java写题.
java中高精度实数类 BigDecimal。

BigDecimal add(BigDecimal augend) :加法

BigDecimal subtract(BigDecimal subtrahend) :减法

BigDecimal divide(BigDecimal divisor) :除法   

BigDecimal pow(int n) :乘幂

BigDecimal multiply(BigDecimal multiplicand) :乘法

BigDecimal stripTrailingZeros() 返回数值上等于此小数,但从该表示形式移除所有尾部零的 BigDecimal。

BigDecimal toPlainString() 返回不带指数字段的此 BigDecimal 的字符串表示形式。就是直接显示,不用科学计数法表示。

  1. import java.util.Scanner;
  2. import java.math.BigDecimal;
  3. public class Main { //用Main起名才能在oj上编译通过
  4. public static void main(String[] args){
  5. Scanner cin=new Scanner(System.in);
  6. while(cin.hasNext()){
  7. BigDecimal a=cin.nextBigDecimal();
  8. int b=cin.nextInt();
  9. String s=a.pow(b).stripTrailingZeros().toPlainString();
  10. if(s.charAt(0)=='0')
  11. s=s.substring(1);
  12. System.out.println(s);
  13. }
  14. }
  15. }

在JAVA中有两个类BigInteger和BigDecimal分别表示大整数类和大浮点数类,至于两个类的对象能表示最大范围不清楚,理论上能够表示无限大的数,只要计算机内存足够大。

这两个类都在java.math.*包中,因此每次必须在开头处引用该包。

Ⅰ基本函数:

1.valueOf(parament); 将参数转换为制定的类型

比如 int a=3;

BigInteger b=BigInteger.valueOf(a);

则b=3;

String s=”12345”;

BigInteger c=BigInteger.valueOf(s);

则c=12345;

2.add(); 大整数相加

BigInteger a=new BigInteger(“23”);

BigInteger b=new BigInteger(“34”);

a.     
add(b);

3.subtract(); 相减

4.multiply(); 相乘

5.divide();   
相除取整

6.remainder(); 取余

7.pow();   a.pow(b)=a^b

8.gcd();   最大公约数

9.abs(); 绝对值

10.negate(); 取反数

11.mod(); a.mod(b)=a%b=a.remainder(b);

12.max(); min();

13.punlic int comareTo();

14.boolean equals(); 是否相等

15.BigInteger构造函数:

一般用到以下两种:

BigInteger(String val);

将指定字符串转换为十进制表示形式;

BigInteger(String val,int radix);

将指定基数的 BigInteger 的字符串表示形式转换为 BigInteger

Ⅱ.基本常量:

A=BigInteger.ONE   
1

B=BigInteger.TEN   
10

C=BigInteger.ZERO   0

HDU1063 大数 java的更多相关文章

  1. HDU 1715 大数java

    大菲波数 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  2. HDU1134/HDU1133 递推 大数 java

    Game of Connections Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  3. How Many Fibs_hdu_1316(大数).java

    How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  4. Integer Inquiry_hdu_1047(大数).java

    Integer Inquiry Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. 大数java(pow)

    Problems involving the computation of exact values of very large magnitude and precision are common. ...

  6. java中大数的一些基本运算

    import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(S ...

  7. 大数问题,通常用JAVA

    e.g. HDU1002 简单加法 import java.math.BigInteger; import java.util.Scanner; public class Main { public ...

  8. java求两个数中的大数

    java求两个数中的大数 java中的max函数在Math中 应用如下: int a=34: int b=45: int ans=Math.max(34,45); 那么ans的值就是45.

  9. CF1245 A. Good ol' Numbers Coloring(java与gcd)

    题意:给定数字A和数字B,问是否满足gcd(A,B)==1. 思路:可以直接写函数gcd.也可以用大数自带的gcd功能. 代码1: /* @author nimphy @create 2019-11- ...

随机推荐

  1. Codeforces Round #198 (Div. 1) D. Iahub and Xors 二维树状数组*

    D. Iahub and Xors   Iahub does not like background stories, so he'll tell you exactly what this prob ...

  2. T-SQL中只截取日期的日期部分和日期的时间部分

    SQL Server 中截取日期的日期部分: ),) SQL Server 中截取日期的时间部分: ),) ),DD_133,)

  3. telnet时显示:允许更多到 telnet 服务器的连接。请稍候再试

    telnet时显示:允许更多到 telnet 服务器的连接.请稍候再试    解决办法: windows自带telnet服务器默认的最大连接数为2,要想修改该设置,可以在命令行键入tlntadmn c ...

  4. 模数转换(A/D)和数模转换(D/A) 图示

    (从书中截图) 在时间域和频率域中示意图: 1.A/D转换 2.D/A转换

  5. PHP 不使用第三个变量实现交换两个变量的值

    //字符串版本 结合使用substr,strlen两个方法实现$a="a";$b="b";echo '交换前 $a:'.$a.',$b:'.$b.'<br ...

  6. SpringBoot使用velocity模板引擎

    https://my.oschina.net/universsky/blog/704446

  7. 后缀数组 UVA 11107 Life Forms

    题目链接 题意:训练指南P223 分析:二分长度,把所有字符串连成一个字符串,中间用不同的字符分隔(这是为了保证匹配长度始终在一个字符串内).height数组分段,vis数组标记哪些字符串被访问了,如 ...

  8. Python基础1-Python环境搭建

    Python环境搭建首先通过终端窗口输入 "python" 命令来查看本地是否已经安装Python以及Python的安装版本: 若未安装则需要下载安装,下面为linux和windo ...

  9. HDU5853 Jong Hyok and String(二分 + 后缀数组)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5853 Description Jong Hyok loves strings. One da ...

  10. mysql 如何判断 "字符串" 是否为 "数字"

    这个问题有点怪 ,但很多时候我们会以字符串的形式存储数字 , 反过来我们用字符串进行数学运算时, 好像也不会出错 . 除非 , 用作数学运算的字符串不能转换成数字 .但是我们改如何判断字符串是否能转换 ...