Given a very large number N, we need to count the total ways such that if we divide the number into two parts a and b, the first part a can be obtained by integral division of second b by some power p of 10 and p>=0.
1 <= No of digits in N <= .
Input : 220 Output : 1 220 can be divided as a = 2 and b = 20 such that for p = 1, b/10 = a. Input : 1111 Output : 2 We get answer 2 because we need to consider integral division. Let's consider the first partition a = 1, b = 111. for p = 2, b/pow(10,p) = a thus this is a valid partition. now a = 11, b = 11. for p = 0, b/pow(10,p) = a thus this too is a valid combination. Input : 2202200 Output : 2 for a = 2 b = 202200, p = 5 and a = 220, b = 2200, p = 1
Since the number can be very large to be contained even in a long long int we will store it as a string. According to the conditions mentioned in the problem, division is the floor function. A simple and inefficient approach will be to divide the string into two substrings then convert those to integer and perform division.
An efficient method to do it will be to use the string compare function to match the most significant digits of the two strings and ignore the rest( floor function). Below is the implementation of this idea :
- Number of ways to split a binary number such that every part is divisible by 2
- Highest power of two that divides a given number
- Given a HUGE number check if it's a power of two.
- Minimum number of sub-strings of a string such that all are power of 5
- Minimum removals in a number to be divisible by 10 power raised to K
- DFA based division
- Program to compute division upto n decimal places
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 3
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 2
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 1
- Manacher's Algorithm - Linear Time Longest Palindromic Substring - Part 4
- Find sub-string with given power
- Find whether a given integer is a power of 3 or not
- Power Set in Lexicographic order
- Quotient and remainder dividing by 2^k (a power of 2)
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.