HDU1063 大数 java
Exponentiation
Time Limit: 2000/500 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9107 Accepted Submission(s): 2654
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 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 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.
.00000005148554641076956121994511276767154838481760200726351203835429763013462401
43992025569.928573701266488041146654993318703707511666295476720493953024
29448126.764121021618164430206909037173276672
90429072743629540498.107596019456651774561044010001
1.126825030131969720661201
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的更多相关文章
- HDU 1715 大数java
大菲波数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU1134/HDU1133 递推 大数 java
Game of Connections Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- How Many Fibs_hdu_1316(大数).java
How Many Fibs? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- Integer Inquiry_hdu_1047(大数).java
Integer Inquiry Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 大数java(pow)
Problems involving the computation of exact values of very large magnitude and precision are common. ...
- java中大数的一些基本运算
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(S ...
- 大数问题,通常用JAVA
e.g. HDU1002 简单加法 import java.math.BigInteger; import java.util.Scanner; public class Main { public ...
- java求两个数中的大数
java求两个数中的大数 java中的max函数在Math中 应用如下: int a=34: int b=45: int ans=Math.max(34,45); 那么ans的值就是45.
- CF1245 A. Good ol' Numbers Coloring(java与gcd)
题意:给定数字A和数字B,问是否满足gcd(A,B)==1. 思路:可以直接写函数gcd.也可以用大数自带的gcd功能. 代码1: /* @author nimphy @create 2019-11- ...
随机推荐
- 【Android开发日记】Popupwindow 完美demo
Popupwindow 完美demo实现 图示: 关键代码说明: 1.弹出popupwindow,背景变暗 ColorDrawable cd = new ColorDrawable(0x000000) ...
- hdu 1370 Biorthythms 中国剩余定理
Biorhythms Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HTTP协议开发应用-HTTP&XML协议栈开发
Netty HTTP+XML协议栈开发 由于HTTP协议的通用性,很多异构系统间的通信交互采用HTTP协议,通过HTTP协议承载业务数据进行消息交互,例如非常流行的HTTP+XML或者RESTful+ ...
- Angular JS 学习之过滤器
1.过滤器可以使用一个管道字符(|)添加到表达式和指令中: 2.AngularJS过滤器可用于转换数据: **currency:格式化数字为货币格式: **filter:从数组项中选择一个子集: ** ...
- css随记02布局
布局 二栏布局 利用absolute, margin .container { position: relative; } nav { position: absolute; left: 0px; w ...
- mvc-9测试和调试
单元测试 单元测试是比集成测试更底层的测试,用于确保特定的后台代码片段能正常运行; 前端单元测试更多是为了发现浏览器兼容性的bug; 断言 断言是测试的核心,是一些表述代码期望执行结果的语句 //正确 ...
- Python Web 开发的十个框架【转载】
Python 是一门动态.面向对象语言.其最初就是作为一门面向对象语言设计的,并且在后期又加入了一些更高级的特性.除了语言本身的设计目的之外,Python标准 库也是值得大家称赞的,Python甚至还 ...
- 使用递推解题:EOJ2999
题目: Description 给定一个多项式 (ax+by)k,计算多项式展开后 xnym 项的系数. Input 第1行:一个整数T(1≤T≤10)为问题数. 接下来共T行.每行5个整数,分别为a ...
- linux 安装vbox增强工具
首先在虚拟机控制台点设备--------安装增强功能,这样会用虚拟光驱加载增强功能镜象. 然后打开终端,先转到root身份:=================su================= f ...
- Nodejs-搭建Nodejs开发环境
学习nodejs,需要一个好的开发工具,并不想用无智能提示和不友好格式的记事本编写 1. 从www.nodejs.org下载nodejs并安装到指定的目录. 2. 下载一个开发工具, 可以选择webs ...