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 的字符串表示形式。就是直接显示,不用科学计数法表示。

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

在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. 关于SQLSERVER联合查询一点看法

    首先看一段代码 这个数据库表我就不发了,这段代码的意思是:查询Book表中大于该类图书价格平均值的图书信息, 先看()里的内容,我一个表起了两个别名,让这个表的相同的id相等,查出平均分,然后再看() ...

  2. scrollTo 和 scrollBy

      涉及到滑动,就涉及到VIEW,大家都知道,Android的UI界面都是由一个一个的View以及View的派生类组成,View作为基类,而常用的布局里面的各种布局就是它派生出来的ViewGroup的 ...

  3. Servlet部分细节介绍

    1 Servlet与线程安全    因为一个类型的Servlet只有一个实例对象,那么就有可能会出现一个Servlet同时处理多个请求,那么Servlet是否为线程安全的呢?答案是:"不是线 ...

  4. mysql注入小测试

    转自:http://www.jb51.net/article/46163.htm 在开发网站的时候,出于安全考虑,需要过滤从页面传递过来的字符.通常,用户可以通过以下接口调用数据库的内容:URL地址栏 ...

  5. Jmeter之JDBC请求(四)

    我们常用的Jmeter中的功能又HTTP请求.JDBC Request.SOAP/XML -RPC Request,这3个请求, 现在就为大家介绍下 什么是JDBC请求 首先,大家右键点击“测试计划” ...

  6. Codeforces Round #356 (Div. 2)-A

    A. Bear and Five Cards 题目链接:http://codeforces.com/contest/680/problem/A A little bear Limak plays a ...

  7. java.net.SocketException: No buffer space available

    https 访问url在调用量不大的情况下 java.net.SocketException: No buffer space available (maximum connections reach ...

  8. 05_Java异常(Exception)

    1. 异常的概念 1.1什么是异常 异常指的是程序运行时出现的不正常情况. 1.2异常的层次 Java的异常类是处理运行时的特殊类,每一种异常对应一种特定的运行错误.所有Java异常类都是系统类库中E ...

  9. delphi公共函数 UMyPubFuncFroc--版权所有 (C) 2008 勇者工作室

    {*******************************************************} { } { Delphi公用函数单元 } { } { 版权所有 (C) 2008 勇 ...

  10. enum枚举类型的使用

    修饰符为public static enum,不用加final,否则提示错误. 枚举类的所有实例必须在枚举类中显式列出(,分隔,; 结尾).列出的实例系统会自动添加 public static fin ...