- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check whether the number can be made perfect square after adding 1 in Python
Suppose we have a number n. We have to check whether the number can be a perfect square number by adding 1 with it or not.
So, if the input is like n = 288, then the output will be True as after adding 1, it becomes 289 which is same as 17^2.
To solve this, we will follow these steps −
- res_num := n + 1
- sqrt_val := integer part of square root of(res_num)
- if sqrt_val * sqrt_val is same as res_num, then
- return True
- return False
Let us see the following implementation to get better understanding −
from math import sqrt def solve(n): res_num = n + 1 sqrt_val = int(sqrt(res_num)) if sqrt_val * sqrt_val == res_num: return True return False n = 288 print(solve(n))
- Check if given number is perfect square in Python
- Check whether the number formed by concatenating two numbers is a perfect square or not in Python
- Check whether given string can be generated after concatenating given strings in Python
- Check if a number in a list is perfect square using Python
- Find the smallest number by which 5103 can be divided to get a perfect square. Also find the square root of the perfect square so obtained.
- Check if a number is perfect square without finding square root in C++
- Program to check number is perfect square or not without sqrt function in Python
- Program to check whether one string can be 1-to-1 mapped into another string in Python
- Check Perfect Square or Not
- Program to check whether palindrome can be formed after deleting at most k characters or not in python
- Check whether the file can be read in Java
- Find the smallest number by which 396 must be divided to obtain a perfect square. Also find the square root of the perfect square so obtained.
- Write the smallest number that must be subtracted from 9400 to obtain a perfect square.Find this perfect square and its square root.
- Find minimum number to be divided to make a number a perfect square in C++