高精度 java的一些题
poj 1001 Exponentiation
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNextBigDecimal()) {
BigDecimal a = in.nextBigDecimal();
int b = in.nextInt();
a = a.pow(b);
a = a.stripTrailingZeros();
String ans = a.toPlainString();
if(ans.startsWith("0."))
ans = ans.substring(1);
System.out.println(ans);
}
}
}
poj 1503 Integer Inquiry
大数加法
```
import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger a, b, c;
c = BigInteger.valueOf(0);
b = BigInteger.valueOf(0);
while(true) {
a = in.nextBigInteger();
if(a.equals(c))
break;
b = b.add(a);
}
System.out.println(b);
}
}
<h3> <a href = "http://acm.hdu.edu.cn/showproblem.php?pid=1042", target = "_blank">hdu 1042 N! </a> </h3>
<h3> 大数乘法 </h3>
import java.util.;
import java.math.;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger ans, c;
while(in.hasNextInt()) {
int n = in.nextInt();
ans = BigInteger.valueOf(1);
for(int i = n; i >= 1; i--) {
c = BigInteger.valueOf(i);
ans = ans.multiply(c);
}
System.out.println(ans);
}
}
}
<h3> <a href = "http://acm.hdu.edu.cn/showproblem.php?pid=1316", target = "_blank">hdu 1316 How Many Fibs? </a> </h3>
<h3> 大数乘法, 求给出的两个数之间有多少个fib数</h3>
import java.util.;
import java.math.;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
BigInteger f[] = new BigInteger[505];
f[1] = new BigInteger("1");
f[2] = new BigInteger("2");
for(int i = 3; i<= 500; i++) {
f[i] = f[i-1].add(f[i-2]);
}
BigInteger a, b, zero;
zero = BigInteger.valueOf(0);
while(true) {
a = in.nextBigInteger();
b = in.nextBigInteger();
if(a.equals(zero) && b.equals(zero)) {
break;
}
int tmp = 0;
for(int i = 1; i <= 500; i++) {
if(f[i].compareTo(a)>=0 && f[i].compareTo(b)<=0)
tmp++;
}
System.out.println(tmp);
}
}
}
高精度 java的一些题的更多相关文章
- 【Java每日一题】20170106
20170105问题解析请点击今日问题下方的"[Java每日一题]20170106"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170105
20170104问题解析请点击今日问题下方的"[Java每日一题]20170105"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170104
20170103问题解析请点击今日问题下方的"[Java每日一题]20170104"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20170103
20161230问题解析请点击今日问题下方的"[Java每日一题]20170103"查看(问题解析在公众号首发,公众号ID:weknow619) package Jan2017; ...
- 【Java每日一题】20161230
// 20161229问题解析请点击今日问题下方的"[Java每日一题]20161230"查看(问题解析在公众号首发,公众号ID:weknow619)package Dec2016 ...
- 【Java每日一题】20161229
package Dec2016; import java.util.ArrayList; import java.util.List; public class Ques1229 { public s ...
- 【Java每日一题】20161228
package Dec2016; import java.util.ArrayList; import java.util.List; public class Ques1228 { public s ...
- 【Java每日一题】20161227
package Dec2016; public class Ques1227 { public static void main(String[] args){ } { c = 1; } int c ...
- 【Java每日一题】20161226
package Dec2016; public class Ques1226 { static{ num = 1; } public static int num = 2; public static ...
随机推荐
- TextField的所有属性和方法(转)
转自:http://tsyouaschen.iteye.com/blog/600255 表一 TextField 对象的方法 方法 说明TextField.addListener 加入接收触发事件如文 ...
- Python基础之 urllib模块urlopen()与urlretrieve()的使用方法详解。
Python urllib模块urlopen()与urlretrieve()的使用方法详解 1.urlopen()方法urllib.urlopen(url[, data[, proxies]]) ...
- PHP Version之PHP5.2.x到5.3.x
不向下兼容的变化 1. 在5.3的所有绑定扩展中应用了新的内部参数解析API,当给函数传递不兼容的参数时将返回NULL,但有些例外,比如函数get_class()在出现错误时返回FALSE 2. ...
- 有了bootstrap,为什么还要做amaze ui
1.Bootstrap介绍Bootstrap,来自 Twitter,是目前很受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加 ...
- raspberrypi VNC server
安装apt-get install tightvncserver tightvnc-java 启动vncserver -name vnc_raspi -depth 24 -geometry 800x6 ...
- @Html.ActionLink 添加样式 html标签
@Html.ActionLink(item.MessageTitle, "Detail", "News",new { MessageId = item.Mess ...
- knockout computed实例
function Privilege(options) { var self = this; self.fieldId = options.fieldId; self.readAccessType = ...
- HibernateTransactionManager 和 hibernateTemplate的区别
在applicationContext.xml中有如下配置: <bean id="hibernateTemplate" class="org.springframe ...
- JavaEE Tutorials (20) - 企业应用安全入门
20.1企业应用的基本安全任务31620.2保护企业bean安全316 20.2.1使用声明式安全保护企业bean安全318 20.2.2通过编程方式保护企业bean安全321 20.2.3传播安全身 ...
- RHEL Channel Bonding
1. 添加 kernel 模块 RHEL5上编辑 /etc/modprobe.conf 加入 alias bond0 bonding options bond0 miimon=100 mode=1 ...