Given an integer X which is a perfect square, the task is to find the square root of it by using long division method.
Input: N = 484
222 = 484
Input: N = 144
122 = 144
Long division is a very common method to find the square root of a number. The following is the stepwise solution for this method:
- Divide the digits of the number into pairs of segments starting with the digit in the units place. Let’s identify each pair and the remaining final digit(in case there is an odd count of digits in the number) as a segment.
1225 is divided as (12 25)
- After dividing the digits into segments, start from the leftmost segment. The largest number whose square is equal to or just less than the first segment is taken as the divisor and also as the quotient (so that the product is the square).
9 is the closest perfect square to 12, the first segment 12
- Subtract the square of the divisor from the first segment and bring down the next segment to the right of the remainder to get the new dividend.
12 - 9 = 3 is concatenated with next segment 25. New dividend = 325
- Now, the new divisor is obtained by taking two times the previous quotient(which was 3 in the above example as 32 = 9) and concatenating it with a suitable digit which is also taken as the next digit of the quotient, chosen in such a way that the product of the new divisor and this digit is equal to, or just less than the new dividend.
Two times quotient 3 is 6.
65 times 5 is 325 which is closest to the new dividend.
- Repeat steps (2), (3) and (4) till all the segments have been taken up. Now, the quotient so obtained is the required square root of the given number.
Below is the implementation of the above approach:
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- C program to find square root of a given number
- Find Square Root under Modulo p | Set 1 (When p is in form of 4*i + 3)
- Babylonian method for square root
- Find Square Root under Modulo p | Set 2 (Shanks Tonelli algorithm)
- Find square root of number upto given precision using binary search
- Square root of a number by Repeated Subtraction method
- Check if a number is perfect square without finding square root
- Fast method to calculate inverse square root of a floating point number in IEEE 754 format
- Find root of a number using Newton's method
- Square root of an integer
- Square root of a number using log
- Program to find root of an equations using secant method
- Java Math subtractExact(long x, long y) method
- Fast inverse square root
- Program to calculate Root Mean Square
- Square root of a number without using sqrt() function
- Floor square root without using sqrt() function : Recursive
- Euler's criterion (Check if square root under modulo p exists)
- Find the number after successive division
- Find Quotient and Remainder of two integer without using division operators
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.