| 1. |
Numbers which end in 0, 1,4,5 or 6 are always perfect squares.Thesaures of numharc andinni 1 un |
|
Answer» Answer: Step-by-step explanation: Check whether the number can be made perfect SQUARE after adding 1 Given an integer N, the task is to check whether N the given number can be made a perfect square after adding 1 to it. Examples: Input: 3 Output: Yes 3 + 1 = 4 which is a perfect square i.e. 22 Input: 5 Output: No 5 + 1 = 6 which is not a perfect square. Recommended: Please try your approach on {IDE} first, before moving on to the solution. Approach: Check whether n + 1 is a perfect square or not by taking the square root of n + 1 and checking whether it is an integer. If it is then n + 1 is a perfect square and n is a sunny number. // C++ implementation of the approach #include using namespace std;
// Function that returns true // if x is a perfect square bool isPerfectSquare(long double x) {
// Find FLOATING point value of // square root of x long double sr = sqrt(x);
// If square root is an integer return ((sr - floor(sr)) == 0); }
// Function that returns true // if n is a sunny number bool isSunnyNum(INT n) {
// If (n + 1) is a perfect square if (isPerfectSquare(n + 1)) |
|