hdu 1316 http://acm.hdu.edu.cn/showproblem.php?pid=1316
统计[a,b]范围内有多少个Fib数
import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
BigInteger f[]=new BigInteger[501];
f[1]=new BigInteger("1");
f[2]=new BigInteger("2");
for(int i=3;i<501;i++)
f[i]=f[i-1].add(f[i-2]);
while(cin.hasNext()){
BigInteger a=cin.nextBigInteger();
BigInteger b=cin.nextBigInteger();
if(a.equals(BigInteger.valueOf(0))&&b.equals(BigInteger.valueOf(0)))
break;
int num=0;
for(int i=1;i<=500;i++){
if(a.compareTo(f[i])<=0&&b.compareTo(f[i])>=0)
num++;
}
System.out.println(num);
}
}
}
hdu 1715 http://acm.hdu.edu.cn/showproblem.php?pid=1715
直接求菲波数
import java.math.BigInteger;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]){
BigInteger f[]=new BigInteger[1010];
f[1]=new BigInteger("1");
f[2]=new BigInteger("1");
for(int i=3;i<1001;i++)
f[i]=f[i-1].add(f[i-2]);
Scanner cin=new Scanner(System.in);
int tc;
tc=cin.nextInt();
while(tc-->0)
{
int a=cin.nextInt();
System.out.println(f[a]);
}
}
}
hdu 1753 http://acm.hdu.edu.cn/showproblem.php?pid=1753
求高精度A+B的值
import java.math.BigDecimal;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]){
Scanner cin=new Scanner(System.in);
while(cin.hasNext()){
BigDecimal a=cin.nextBigDecimal();
BigDecimal b=cin.nextBigDecimal();
BigDecimal c=a.add(b);
String res=c.stripTrailingZeros().toPlainString();
if(res.startsWith("0")){//开头是否有0
res=res.substring(1);
}
System.out.println(res);
}
}
}