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- ...
随机推荐
- java的安装环境配置详细步骤
--------------------声明,如果你有什么建议或者不懂的地方,欢迎回复,我们可以互相学习,转载请注明出处,谢谢---------------- 首先得安装jdk(Java Develo ...
- CSS 基本1
HTML元素可以分为两种: 块级元素 内联元素(行内元素) 两者的区别在于以下三点: 块级元素会独占一行(即无法与其他元素显示在同一行内,除非你显示修改元素的 display 属性),而内联元素则都会 ...
- 【转】最近搞Hadoop集群迁移踩的坑杂记
http://ju.outofmemory.cn/entry/237491 Overview 最近一段时间都在搞集群迁移.最早公司的hadoop数据集群实在阿里云上的,机器不多,大概4台的样子,据说每 ...
- PHP 使用 OSS 批量上传图片
<?php set_time_limit(0); // 引入自动加载类// 确保路径是否正确 require_once 'autoload.php'; // 确定参数 需要申请 $accessK ...
- css3 -- 属性选择器
属性选择器: 1.CSS属性选择器 属性选择器E[attr="value"]{} 包含属性选择器E[attr~="value"]{} 2.CSS3的新属性选择器 ...
- 【转】linux network namespace 学习
原文地址:https://segmentfault.com/a/1190000004059167 介绍 在专业的网络世界中,经常使用到Virtual Routing and Forwarding(VR ...
- BestCoder Round #65
博弈 1002 ZYB's Game 题意:中文 分析:假定两个人是绝顶聪明的,一定会采取最优的策略.所以如果选择X的左边的一个点,那么后手应该选择X的右边对称的点,如果没有则必输,否则必胜,然后再分 ...
- iOS 初学UITableView、UITableViewCell、Xib
注意事项: 1.一个.xib里面最多设置一个cell 2.要仔细调整自动布局,其实它不太好用 3.记得设置<UITableViewDataSource>委托 4.记得在ViewContro ...
- 每天一个linux命令---tar
解包/打包语法:tar [主选项+辅选项] 文件或者目录 使用该命令时,主选项是必须要有的,它告诉tar要做什么事情,辅选项是辅助使用的,可以选用. 主选项: c 创建新的档案文件.如果用户想备份一个 ...
- linux 安装程序
tar文件打开 tar -xvf myfile.tar bz2文件打开