Given a very large number, the task is to write a program to compute its square.
9999*9999 = 99980001
45454545*45454545 = 2066115661157025
Naive Approach: A naive approach is to calculate the squares my multiplying the number with itself. But in C++, if the input is a large number, the resultant square will overflow.
Efficient Approach: An efficient approach is to store the number as strings, and perform multiplication of two large numbers.
Below is the implementation of the above approach:
- Divide large number represented as string
- Check whether a large number represented as array is divisible by Y
- Multiply Large Numbers represented as Strings
- Modulo power for large numbers represented as strings
- Evaluate a boolean expression represented as string
- Product of nodes at k-th level in a tree represented as string
- Modulo of a large Binary String
- Add 1 to number represented as array | Recursive Approach
- Check if a number can be represented as a sum of 2 triangular numbers
- Sum of two numbers where one number is represented as array of digits
- Find the smallest positive number which can not be represented by given digits
- Check in binary array the number represented by a subarray is odd or even
- Factorial of a large number
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Perfect Square String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.