Given an integer N in form of string str consisting of more than 100 digits, the task is to store the value for performing an arithmetic operation and print the given integer.
Input: str = “54326789013892014531903492543267890138920145319034925432678901389201”
Input: str = “7890138920145319034925432678907890138920145319034925432678901903492543267890”
No data type is present in C++ to store 10100. So, the idea is to use get the input as string (as string can be of any length) and then convert this string into an array of digits of the length same as the length of string. Storing the big integer into an integer array will help to perform some basic arithmetic on that number.
Below are the steps:
- Take the large number as input and store it in a string.
- Create an integer array arr of length same as the string size.
- Iterate over all characters (digits) of string str one by one and store that digits in the corresponsing index of the array arr
arr[i] = str[i] – ‘0’;
// Here ‘0’ represents the digit 0, and
// str[i] – ‘0’ = ASCII(str[i]) – ASCII(‘0’) = ASCII(str[i] – 48
- Using the above step, we can store very very large number for doing any arithmetic operations.
Below is the implementation of the above approach:
Time Complexity: O(K), K is the number of digits in the number
Auxiliary Space: O(K), K is the number of digits in the number
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Number of factors of very large number N modulo M where M is any prime number
- Check whether a very large number of the given form is a multiple of 3.
- Print all K digit repeating numbers in a very large number
- Print all 3 digit repeating numbers in a very large number
- GCD of two numbers when one of them can be very large
- Find (a^b)%m where 'a' is very large
- Recursive sum of digit in n^x, where n and x are very large
- Find (a^b)%m where 'b' is very large
- Series summation if T(n) is given and n is very large
- Comparing X^Y and Y^X for very large values of X and Y
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Check if a large number can be divided into two or more segments of equal sum
- Count number of rotated strings which have more number of vowels in the first half than second half
- Multiply large integers under large modulo
- Find smallest possible Number from a given large Number with same count of digits
- Number of triangles in a plane if no more than two points are collinear
- Numbers of Length N having digits A and B and whose sum of digits contain only digits A and B
- Minimum digits to be removed to make either all digits or alternating digits same
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Given a large number, check if a subsequence of digits is divisible by 8
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.