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:
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.
- 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
- Find all Factors of Large Perfect Square Natural Number in O(sqrt(sqrt(N))
- Evaluate a boolean expression represented as string
- Product of nodes at k-th level in a tree represented as string
- Reverse all the word in a String represented as a Linked List
- Product of nodes at k-th level in a tree represented as string using Recursion
- Modulo of a large Binary String
- Find smallest possible Number from a given large Number with same count of digits
- Sum of two numbers where one number is represented as array of digits
- Add 1 to number represented as array | Recursive Approach
- Check if a number can be represented as a sum of 2 triangular numbers
- 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
- Smallest number greater than n that can be represented as a sum of distinct power of k
- Factorial of a large number
- Check if a large number is divisible by 4 or not
- To check whether a large number is divisible by 7
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.