標籤:
SDUT2525:A-B (模板題)
import java.util.Scanner;import java.math.*;public class Main{ public static void main(String[] args) { Scanner ci = new Scanner(System.in); BigInteger a; BigInteger b; while(ci.hasNext()) { a=ci.nextBigInteger(); b=ci.nextBigInteger(); System.out.println(a.subtract(b)); } ci.close(); }}
SDUT3134:大數模數
import java.util.Scanner;import java.math.*;public class Main{ public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { BigInteger a,b; a=cin.nextBigInteger(); b=cin.nextBigInteger(); System.out.println(a.mod(b)); } cin.close(); }}
View Code
SDUT2613:大數加法
import java.util.Scanner;import java.math.*;public class Main{ public static void main(String[] args) { Scanner cin = new Scanner(System.in); while(cin.hasNext()) { BigInteger a,b; a=cin.nextBigInteger(); b=cin.nextBigInteger(); System.out.println(a.add(b)); } cin.close(); }}
View Code
SDUT2763: 好玩的五次方
這個題還是比較好的,利用了math中的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); int n,t,cnt,ff; while(cin.hasNext()) { n=cin.nextInt(); cnt=0; ff=-1; int[] a=new int[n]; int[] b=new int[n]; for(int i=0;i<n;i++) { a[i]=cin.nextInt(); } Arrays.sort(a); for(int i=0;i<n;i++) { if(a[i]>0) b[cnt++]=a[i]; } for(int i=0;i<cnt;i++) { if(b[i]!=(i+1)) { ff=i+1; break; } } if(ff==-1) ff=cnt+1; BigInteger sum=BigInteger.valueOf(ff); System.out.println(sum.pow(5)); } cin.close(); }}
SDUT中大數實現的題目,持續更新(JAVA實現)