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
- Find all Factors of Large Perfect Square Natural Number in O(sqrt(sqrt(N))
- Evaluate a boolean expression 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
- 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
- Smallest number greater than n that can be represented as a sum of distinct power of k
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.