nyoj-155-求高精度幂(java大数)
1 import java.util.*; 2 import java.math.*; 3 public class Main{ 4 5 public static void main(String[] args) { 6 Scanner cin = new Scanner(System.in); 7 while (cin.hasNext()) { 8 BigDecimal numa = cin.nextBigDecimal(); 9 int numb = cin.nextInt(); 10 String str = numa.pow(numb).stripTrailingZeros().toPlainString(); 11 if (str.startsWith("0.")) {//如果开头是0.那么从小数点开始输出 12 System.out.println(str.substring(1)); 13 } else { 14 System.out.println(str); 15 } 16 } 17 } 18 }