標籤:
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(); }}
UVA+POJ中大數實現的題目,持續更新(JAVA實現)