UVA10494:If We Were a Child Again 大数除法加取余
import java.util.Arrays;
import java.util.Scanner;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
BigInteger a,b;
String s;
while(cin.hasNext())
{
a=cin.nextBigInteger();
s=cin.next();
b=cin.nextBigInteger();
if(s.equals("/"))
{
System.out.println(a.divide(b));
}
else if(s.equals("%"))
{
System.out.println(a.mod(b));
}
}
cin.close();
}
}
UVA748&&HDU1063: Exponentiation 大数的乘法,pow
import java.util.Arrays;
import java.util.Scanner;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
BigDecimal a;
int n;
while(cin.hasNext())
{
a=cin.nextBigDecimal();
n=cin.nextInt();
BigDecimal cnt=a.pow(n).stripTrailingZeros();
System.out.println( cnt.toPlainString().replaceAll("^0", "") );
}
cin.close();
}
}