HDU1002:大数加法,PE了N次
import java.util.Scanner;
import java.math.*; public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int T;
T=cin.nextInt();
for(int z=1;z<=T;z++)
{
if(z!=1) System.out.println();
BigInteger a,b;
a=cin.nextBigInteger();
b=cin.nextBigInteger();
System.out.println("Case "+z+":");
System.out.println(a+" + "+b+" = "+a.add(b)); }
cin.close();
} }
HDU1042:N!大数乘法
import java.util.Scanner;
import java.math.*; import javax.naming.ldap.HasControls; public class Main{ public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int t;
while(cin.hasNext())
{
BigInteger n=BigInteger.valueOf(1);
t=cin.nextInt();
for(int i=2;i<=t;i++)
{
n=n.multiply(BigInteger.valueOf(i));
}
System.out.println(n);
} } }
HDU1316:How Many Fibs?
import java.math.*;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
BigInteger []f=new BigInteger[1020];
f[0]=BigInteger.valueOf(1);
f[1]=BigInteger.valueOf(1);
f[2]=BigInteger.valueOf(2);
for(int i=3;i<1019;i++)
f[i]=f[i-1].add(f[i-2]);
BigInteger a,b;
int sum;
while(cin.hasNextBigInteger())
{
a=cin.nextBigInteger();
b=cin.nextBigInteger();
if(a.compareTo(BigInteger.ZERO)==0&&b.compareTo(BigInteger.ZERO)==0) break;
sum=0;
for(int i=1;i<=1015;i++)
{
if(f[i].compareTo(a)>=0&&f[i].compareTo(b)<=0)
{
sum++;
}
if(f[i].compareTo(b)>0) break;
}
System.out.println(sum);
}
cin.close();
} }
HDU1753: 大明 A+B 大数加法加一些函数
import java.math.*;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
BigDecimal a,b;
while(cin.hasNextBigDecimal())
{
a=cin.nextBigDecimal();
b=cin.nextBigDecimal();
System.out.println(a.add(b).stripTrailingZeros().toPlainString());
}
cin.close();
} }