1 ImportJava.math.BigInteger; 2 3 Public classBigInt {4 BigInteger M1; 5 BigInteger m2; 6 BigInteger m3; 7 8 BigInt (string s1, string s2) {9M1 =NewBigInteger (S1); TenM2 =NewBigInteger (S2); One } A - Public voidAdd () { -M3 =M1.add (m2); theSystem.out.println ("Two number of and for:" +m3); - } - - Public voidCut () { +M3 =m1.subtract (m2); -System.out.println ("The difference of two numbers is:" +m3); + } A at Public voidMultiply () { -M3 =m1.multiply (m2); -SYSTEM.OUT.PRINTLN ("The product of two numbers is:" +m3); - } - - Public voiddivide () { inM3 =m1.divide (m2); -System.out.println ("Two-digit quotient:" +m3); to } + - Public voidFactorcount () { the intCount = 0; * for(BigInteger i = biginteger.valueof (2); I.compareto (M1) < 0; i =I $ . Add (Biginteger.one)) { Panax Notoginseng if(M1.remainder (i). Equals (Biginteger.zero)) { -++count; the } + } ASYSTEM.OUT.PRINTLN (M1 + "Number of factors:" +count); the } + - $ Public Static voidMain (string[] args) $ { -String num1= "123456789123456789123456789"; -String num2= "987654321987654321987654321"; theBigInt bigint=NewBigInt (num1,num2); - Wuyi Bigint.add (); the bigint.cut (); - bigint.multiply (); Wu bigint.divide (); - Bigint.factorcount (); About } $}
Operation of two large integers (Java)