is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
You can implement Karatsuba algorithm for large number multiplication.
- bhavik.ambani2013 February 07, 2017Please see the code below for the same.
import java.util.Scanner;
/**
* The Class LargeMultiplication.
*
* @author Bhavik Ambani
*/
public class LargeMultiplication {
/**
* Function to multiply two numbers *.
*
* @param x
* the x
* @param y
* the y
* @return the long
*/
public long multiply(long x, long y) {
int size1 = getSize(x);
int size2 = getSize(y);
/** Maximum of lengths of number **/
int N = Math.max(size1, size2);
/** for small values directly multiply **/
if (N < 10)
return x * y;
/** max length divided, rounded up **/
N = (N / 2) + (N % 2);
/** multiplier **/
long m = (long) Math.pow(10, N);
/** compute sub expressions **/
long b = x / m;
long a = x - (b * m);
long d = y / m;
long c = y - (d * N);
/** compute sub expressions **/
long z0 = multiply(a, c);
long z1 = multiply(a + b, c + d);
long z2 = multiply(b, d);
return z0 + ((z1 - z0 - z2) * m) + (z2 * (long) (Math.pow(10, 2 * N)));
}
/**
* Gets the size.
*
* @param num
* the num
* @return the size
*/
public int getSize(long num) {
int ctr = 0;
while (num != 0) {
ctr++;
num /= 10;
}
return ctr;
}
/**
* Main function *.
*
* @param args
* the arguments
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("LargeMultiplication Algorithm Test\n");
LargeMultiplication kts = new LargeMultiplication();
/** Accept two integers **/
System.out.println("Enter two integer numbers\n");
long n1 = scan.nextLong();
long n2 = scan.nextLong();
scan.close();
/** Call function multiply of class Karatsuba **/
long product = kts.multiply(n1, n2);
System.out.println("\nProduct : " + product);
}
}