edited by
1,826 views
7 votes
7 votes

Given an integer $n\geq 3$, consider the problem of determining if there exist integers $a,b\geq 2$ such that $n=a^{b}$. Call this the forward problem. The reverse problem is: given $a$ and $b$, compute $a^{b}$ (mod b). Note that the input length for the forward problem is $\lfloor\log n\rfloor + 1$, while the input length for the reverse problem is $\lfloor\log a\rfloor + \lfloor\log b\rfloor + 2$. Which of the following statements is TRUE?

  1. Both the forward and reverse problems can be solved in time polynomial in the lengths of their respective inputs.
  2. The forward problem can be solved in polynomial time, however the reverse problem is $NP$-hard.
  3. The reverse problem can be solved in polynomial time, however the forward problem is $NP$-hard.
  4. Both the forward and reverse problem are $NP$-hard.
  5. None of the above.
edited by

1 Answer

Best answer
10 votes
10 votes

The reverse problem can be solved in polynomial time as $a^b$ requires at most $\log b$ recursive calls using the approach given below:

pow(int a, int b)
{
    if(b%2)
        return a* pow(a*a, b/2);
    else
        return pow(a*a, b/2);
}

Now, the forward problem is also solvable in polynomial time. We need to check for all the roots of $n$  (from $\sqrt n$ till $n^{\frac{1}{\log n}}$) whether it is an integer . But each of these check can be done in $\log n$ time using a binary search on the set of integers from 2..$n$ and so, the overall complexity will be $(\log n)^2$ which is polynomial in $\log n$ ($\log n$ is the size of input). So, (a) must be the answer. 
 

edited by
Answer:

Related questions

39 votes
39 votes
4 answers
3
17 votes
17 votes
2 answers
4