标签:
这几天做了几道用大数的题,发现java来做大数运算十分方便。对acmer来说是十分实用的
1 import java.io.*; 2 import java.math.BigInteger; 3 import java.util.*; 4 public class Main { 5 6 public static void main(String[] args) { 7 // TODO Auto-generated method stub 8 Scanner cin=new Scanner (new BufferedInputStream(System.in)); 9 PrintWriter cout=new PrintWriter(System.out); 10 int t; 11 t=cin.nextInt(); 12 int eg=1; 13 while(t>0) 14 { 15 BigInteger eight=new BigInteger("8"); 16 BigInteger seven=new BigInteger("7"); 17 BigInteger one=new BigInteger("1"); 18 String inp; 19 inp=cin.next(); 20 BigInteger n=new BigInteger(inp); 21 BigInteger ans; 22 BigInteger ans2; 23 ans=n.multiply(n).multiply(eight); 24 ans2=n.multiply(seven); 25 ans=ans.subtract(ans2); 26 ans=ans.add(one); 27 cout.println("Case #"+eg+": "+ans); 28 ++eg; 29 --t; 30 31 } 32 cout.flush(); 33 } 34 35 }
大数的所有计算都是与大数之间进行的
BIgInteger a,b;
a=a.add(b);
a=a.substract(b);
a=a.multiply(b);
a=a.divied(b);
a=a.gcd(b);
标签:
原文地址:http://www.cnblogs.com/superxuezhazha/p/4761854.html