Interview Question


Country: India




Comment hidden because of low score. Click to expand.
1
of 1 vote

given: xy = a + b*lcm + c*gcd
elementry maths: xy = lcm*gcd, on substitution, we get: lcm*gcd = a + b*lcm + c*gcd

on rearranging, we get (gcd - b)(lcm - c) = a + bc.
This is a program of finding all pairs of numbers p,q such that pq = k.
=> lcm - c = x1, gcd - b = x2
=> lcm = x1 + c, gcd = x2 + b

Now xy = lcm*gcd => x*y = (x1+c)(x2+b) Which is again a case of pq = k. Call the same function again and count the number of values found, which is our output.

- ashu February 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

ArrayList<Pair> findProd(int k) {
    ArrayList<Pair> list = new ArrayList<Pair>();
    for (int i = 1; i <= (Integer)Math.sqrt(k); i++) {
         if (k % i == 0) {
             list.add(new Pair(i, k/i));
             list.add(new Pair(k/i, i));
         }
    }

    return list;
}

- ashu February 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Thanks Ashu.............

- saurabh February 19, 2012 | Flag
Comment hidden because of low score. Click to expand.


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

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.

Learn More

Resume Review

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.

Learn More

Mock Interviews

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.

Learn More