Given a number X, find the Smallest Number, which is greater than 1, that divides XX. In the given question, X is always presumed to be greater than 1.
Input: X = 6
Explanation: As, 66 is equal to 46656, which is divisible by 2 and it’s the smallest among all its divisors.
Input: X = 3
Explanation: As, 33 is equal to 27, which is divisible by 3 and it’s the smallest among all its divisors.
The main observation of this problem is that if a number P divides X, then it also divides XX, so we don’t need to calculate the value of XX. What we need to do is to find the smallest number that divides X which will always be a Prime Number.
Below is the implementation of the above approach:
Time Complexity: O(sqrt(X))
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer DSA Live Classes