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(); } }
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(); } }
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(); } }