/*************************************** **********************
* This program uses the divide and conquer method for multiplication.
* 1011*1101
* Coder: jiutian X-Dragon
* Running result:
* H:/Java/algorithm/big integer ~ 1> javac mult. Java
*
* H:/Java/algorithm/big integer ~ 1> JAVA Mult
* 11x13: 143
*
* H:/Java/algorithm/big integer ~ 1>
**************************************** **********************/
Import java. Lang .*;
Class mult {
Public int X, Y; // The two numbers that require product.
// Initialize the two numbers required in this question
Mult (){
X = 11; // 1011 of binary data
Y = 13; // 1101 of Binary
}
//************************************** ************
// Function name getvalue. This function is the main function of this algorithm.
// The reverse return value is the product of the specified number XY.
// According to the formula xy = A * C * 2n + (A-B) (D-C) + AC + bd) * 2n/2 + BD
// There are 3 multiplication, 6 addition, and 2 shift operations in total
//************************************** ************
Public int getvalue (int A, int B, int C, int d ){
Int N = 4; // The number of digits of the desired number
Return (A * C * (2 <(n-1) +
(A-B) * (D-C) + A * C + B * D )*
(2 <(n/2-1) +
B * D );
}
Public static void main (string [] ARGs ){
Int n = 2;
Mult mu = new mult ();
Int A, B, C, D;
// Break down the original Multiplier
A = mu. x> N;
B = mu. X & 3;
C = mu. Y> N;
D = mu. Y & 3;
Int ret = mu. getvalue (A, B, C, D );
// Output result
System. Out. println ("" + Mu. x + "X" + Mu. Y + "Result:" + RET );
}
}