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- ...
随机推荐
- C#分布式缓存Couchbase使用
目前C#业界使用得最多的 Cache 系统主要是 Memcached和 Redis. 这两个 Cache 系统可以说是比较成熟的解决方案,也是很多系统当然的选择. 一.简介 目前C#业界使用得最多的 ...
- How Kafka’s Storage Internals Work
In this post I'm going to help you understand how Kafka stores its data. I've found understanding th ...
- user_jj两条记录改成一条
1.前台index控制器,用user_jj.*add找到,home_ddxx_pcz_cl() 2.前台index控制器,用user_jj.*add找到,tgbz_list_sd_cl(),tgbz_ ...
- nginx、php-fpm、mysql用户权限解析
nginx本身不能处理PHP,它只是个web服务器.当接收到客户端请求后,如果是php请求,则转发给php解释器处理,并把结果返回给客户端.如果是静态页面的话,nginx自身处理,然后把结果返回给客户 ...
- css样式—字体垂直、水平居中
“来,老板娘,给个div瞅瞅”: “好的,宇哥,来了了了”: <div class="tt">啦啦啦</div> “给各样啊,我去”: “是”: .tt{ ...
- 2016.8.16 JQuery学习记录
1.$(document).ready(function(){}); 这个函数会在浏览器加载完页面之后,尽快执行: 2.所有的JQuery函数用有个$开始表示,All jQuery functions ...
- psql-04数据类型(2)
复合类型 PostgreSQL中可以如C语言中的结构体一样定义一个复合类型; 创建 create type person as ( name text, age int, sex boolean ); ...
- react-基础(2)
表单相关 固定的几个属性和事件 value: <input>,<textarea>; checked: <input> typeof checkbox, radio ...
- MVC 异常处理机制
方法一 :web.config配置文件的 system.web 接点下添加,若为On则不会将异常信息反馈到用户,而是友好的跳转到error.htm <customErrors mode=&quo ...
- BZOJ2597 [Wc2007]剪刀石头布(最小费用最大流)
题目大概是说n个人两两进行比赛,问如何安排几场比赛的输赢使得A胜B,B胜C,C胜A这种剪刀石头布的三元组最多. 这题好神. 首先,三元组总共有$C_n^3$个 然后考虑最小化不满足剪刀石头布条件的三元 ...