Given an integer X, the duty is to find out the minimal worth of Y higher than X, such that count of divisors of X and Y have different parities.
Examples:
Enter: X = 5
Output: 9
Clarification: The depend of divisors of 5 and 9 are 2 and three respectively, that are of various parities.Enter: X = 9
Output: 10
Clarification: The counts of divisors of 9 and 10 are three and 4, that are of various parities.
Naive Strategy: The only strategy to unravel the issue is to iterate every quantity ranging from X + 1 till a component with depend of the divisors with parity reverse to that of X is obtained.
Time Complexity: O((1+√X)^{2})
Auxiliary Area: O(1)
Beneath is the implementation of the above strategy:
C++

Java

Environment friendly Strategy: The issue might be solved primarily based on the next observations:
Observe the steps under to unravel the issue:
 Check if X is a perfect square. If discovered to be true, print X + 1.
 In any other case, print (1 + ground(√X))^{2}).
Beneath is the implementation of the above strategy:
C++

Time Complexity: O(1)
Auxiliary Area: O(1)
Consideration reader! Don’t cease studying now. Pay money for all of the necessary DSA ideas with the DSA Self Paced Course at a studentfriendly value and develop into trade prepared.
In the event you like GeeksforGeeks and wish to contribute, you can even write an article utilizing contribute.geeksforgeeks.org or mail your article to [email protected] See your article showing on the GeeksforGeeks most important web page and assist different Geeks.
Please Enhance this text should you discover something incorrect by clicking on the “Enhance Article” button under.