Interesting interview question. .Net

Posted by rahul on Stack Overflow See other posts from Stack Overflow or by rahul
Published on 2010-06-13T05:18:31Z Indexed on 2010/06/13 5:22 UTC
Read the original article Hit count: 286

Filed under:
|
|
|

Coding Problem NumTrans There is an integer K. You are allowed to add to K any of its divisors not equal to 1and K. The same operation can be applied to the resulting number and so on. Notice that starting from the number 4, we can reach any composite number by applying several such operations. For example, the number 24 can be reached starting from 4 using 5 operations: 468121824

You will solve a more general problem. Given integers n and m, return the minimal number of the described operations necessary to transform n into m. Return -1 if m can't be obtained from n.

Definition Method signature: int GetLeastCount (int n, int m)

Constraints N will be between 4 and 100000, inclusive. M will be between N and 100000, inclusive.

Examples 1) 4 576 Returns: 14 The shortest order of operations is: 468121827365481108162243324432576

2) 8748 83462 Returns: 10 The shortest order of operations is: 874813122196832624439366590497873283106834488346083462

3) 4 99991 Returns: -1 The number 99991 can't be obtained because it’s prime!

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET