Find the Next perfect square greater than a given number Last Updated : 24 Jun, 2024 Comments Improve Suggest changes Like Article Like Report Given a number N, the task is to find the next perfect square greater than N.Examples: Input: N = 6Output: 9Explanation: 9 is a greater number than 6 and is also a perfect square Input: N = 9Output: 16 Approach: Find the square root of given N.Calculate its floor value using floor function in C++.Then add 1 to it.Print square of that number.Below is the implementation of above approach: C++ // C++ implementation of above approach #include <iostream> #include<cmath> using namespace std; // Function to find the next perfect square int nextPerfectSquare(int N) { int nextN = floor(sqrt(N)) + 1; return nextN * nextN; } // Driver Code int main() { int n = 35; cout << nextPerfectSquare(n); return 0; } Java // Java implementation of above approach import java.util.*; import java.lang.*; import java.io.*; class GFG { // Function to find the // next perfect square static int nextPerfectSquare(int N) { int nextN = (int)Math.floor(Math.sqrt(N)) + 1; return nextN * nextN; } // Driver Code public static void main(String args[]) { int n = 35; System.out.println (nextPerfectSquare(n)); } } // This code is contributed by Subhadeep Python # Python3 implementation of above approach import math #Function to find the next perfect square def nextPerfectSquare(N): nextN = math.floor(math.sqrt(N)) + 1 return nextN * nextN if __name__=='__main__': N = 35 print(nextPerfectSquare(N)) # this code is contributed by Surendra_Gangwar C# // C# implementation of above approach using System; class GFG { // Function to find the // next perfect square static int nextPerfectSquare(int N) { int nextN = (int)Math.Floor(Math.Sqrt(N)) + 1; return nextN * nextN; } // Driver Code public static void Main() { int n = 35; Console.WriteLine(nextPerfectSquare(n)); } } // This code is contributed // by Shashank JavaScript <script> // Javascript implementation of above approach // Function to find the next perfect square function nextPerfectSquare(N) { let nextN = Math.floor(Math.sqrt(N)) + 1; return nextN * nextN; } // Driver Code let n = 35; document.write(nextPerfectSquare(n)); // This code is contributed by souravmahato348. </script> PHP <?php // PHP implementation // of above approach // Function to find the // next perfect square function nextPerfectSquare($N) { $nextN = floor(sqrt($N)) + 1; return $nextN * $nextN; } // Driver Code $n = 35; echo nextPerfectSquare($n); // This code is contributed by mits ?> Output36 Time Complexity: O(logn) for given number n, as it is using inbuilt sqrt functionAuxiliary Space: O(1) Comment More infoAdvertise with us Next Article Find the Next perfect square greater than a given number M manaschhabra2 Follow Improve Article Tags : Mathematical School Programming DSA maths-perfect-square Practice Tags : Mathematical Similar Reads Largest number that is not a perfect square Given n integers, find the largest number is not a perfect square. Print -1 if there is no number that is perfect square. Examples: Input : arr[] = {16, 20, 25, 2, 3, 10| Output : 20 Explanation: 20 is the largest number that is not a perfect square Input : arr[] = {36, 64, 10, 16, 29, 25| Output : 15+ min read Perfect cube greater than a given number Given a number N, the task is to find the next perfect cube greater than N.Examples: Input: N = 6 Output: 8 8 is a greater number than 6 and is also a perfect cube Input: N = 9 Output: 27 Approach: Find the cube root of given N.Calculate its floor value using floor function in C++.Then add 1 to it.P 3 min read Find the Largest N digit perfect square number in Base B Given two integers N and B, the task is to find the largest N digit numbers of Base B which is a perfect square.Examples: Input: N = 2, B = 10 Output: 81 Explanation: 81 is the largest 2-digit perfect square in base 10.Input: N = 1, B = 8 Output: 4 Explanation: 4 is the largest 1 digit Octal number 9 min read Largest factor of a given number which is a perfect square Given a number N . The task is to find the largest factor of that number which is a perfect square.Examples: Input : N = 420Output : 4Input : N = 100Output : 100A Simple Solution is to traverse all of the numbers in decreasing order from the given number down till 1 and if any of these numbers is a 10 min read Minimum perfect squares to add that sum to given number. Given a positive integer n, the task is to find the minimum number of squares that sum to n. Note: A number can always be represented as a sum of squares of other numbers. Because 1 is a square number and we can always break any number as (1*1 + 1*1 + 1*1 + ... ).Examples : Input: n = 100Output: 1Ex 15+ min read Finding the Missing Digit in the Largest Perfect Square Given a perfect square number with one missing digit represented by an underscore (_). Find the missing digit that when inserted, creates the largest perfect square. Examples: Input: "14_"Output: 4Explanation: The missing digit 4 makes the largest perfect square, 144. Input: 6_25Output: 1Explanation 5 min read Check whether the number can be made perfect square after adding K Given two numbers N and K, the task is to check whether the given number N can be made a perfect square after adding K to it.Examples: Input: N = 7, K = 2 Output: Yes Explanation: 7 + 2 = 9 which is a perfect square. Input: N = 5, K = 3 Output: No Explanation: 5 + 3 = 8 which is not a perfect square 4 min read Largest perfect square number in an Array Given an array of n integers. The task is to find the largest number which is a perfect square. Print -1 if there is no number that is perfect square.Examples:Â Â Input : arr[] = {16, 20, 25, 2, 3, 10} Output : 25 Explanation: 25 is the largest number that is a perfect square. Input : arr[] = {36, 64 7 min read Largest N digit Octal number which is a Perfect square Given a natural number N, the task is to find the largest N digit Octal number which is a perfect square.Examples: Input: N = 1 Output: 4 Explanation: 4 is the largest 1 digit Octal number which is also perfect squareInput: N = 2 Output: 61 Explanation: 49 is the largest number which is a 2-Digit Oc 10 min read Minimum digits to remove to make a number Perfect Square Given an integer n, we need to find how many digits remove from the number to make it a perfect square. Examples : Input : 8314 Output: 81 2 Explanation: If we remove 3 and 4 number becomes 81 which is a perfect square. Input : 57 Output : -1 The idea is to generate all possible subsequences and ret 9 min read Like