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 <= .

**Examples:**

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 considerintegraldivision. 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 :

## C++

`#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// c++ function to count ways to divide a ` `// string in two parts a and b such that ` `// b/pow(10, p) == a ` `int` `calculate(string N) ` `{ ` ` ` `int` `len = N.length(); ` ` ` `int` `l = (len) / 2; ` ` ` `int` `count = 0; ` ` ` ` ` `for` `(` `int` `i = 1; i <= l; i++) { ` ` ` ` ` `// substring representing int a ` ` ` `string s = N.substr(0, i); ` ` ` ` ` `// no of digits in a ` ` ` `int` `l1 = s.length(); ` ` ` ` ` `// consider only most significant ` ` ` `// l1 characters of remaining string ` ` ` `// for int b ` ` ` `string t = N.substr(i, l1); ` ` ` ` ` `// if any of a or b contains leading 0s ` ` ` `// discard this combination ` ` ` `if` `(s[0] == ` `'0'` `|| t[0] == ` `'0'` `) ` ` ` `continue` `; ` ` ` ` ` `// if both are equal ` ` ` `if` `(s.compare(t) == 0) ` ` ` `count++; ` ` ` `} ` ` ` `return` `count; ` `} ` ` ` `// driver function to test above function ` `int` `main() ` `{ ` ` ` `string N = ` `"2202200"` `; ` ` ` `cout << calculate(N); ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to count ways to divide a ` `// String in two parts a and b such that ` `// b/pow(10, p) == a ` `import` `java.util.*; ` ` ` `class` `GFG ` `{ ` `static` `int` `calculate(String N) ` `{ ` ` ` `int` `len = N.length(); ` ` ` `int` `l = (len) / ` `2` `; ` ` ` `int` `count = ` `0` `; ` ` ` ` ` `for` `(` `int` `i = ` `1` `; i <= l; i++) ` ` ` `{ ` ` ` ` ` `// subString representing int a ` ` ` `String s = N.substring(` `0` `, i); ` ` ` ` ` `// no of digits in a ` ` ` `int` `l1 = s.length(); ` ` ` ` ` `// consider only most significant ` ` ` `// l1 characters of remaining String ` ` ` `// for int b ` ` ` `String t = N.substring(i, l1 + i); ` ` ` ` ` `// if any of a or b contains leading 0s ` ` ` `// discard this combination ` ` ` `if` `(s.charAt(` `0` `) == ` `'0'` `|| t.charAt(` `0` `) == ` `'0'` `) ` ` ` `continue` `; ` ` ` ` ` `// if both are equal ` ` ` `if` `(s.compareTo(t) == ` `0` `) ` ` ` `count++; ` ` ` `} ` ` ` `return` `count; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `String N = ` `"2202200"` `; ` ` ` `System.out.print(calculate(N)); ` `} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to count ways to divide ` `# a string in two parts a and b such that ` `# b/pow(10, p) == a ` ` ` `def` `calculate( N ): ` ` ` `length ` `=` `len` `(N) ` ` ` `l ` `=` `int` `((length) ` `/` `2` `) ` ` ` `count ` `=` `0` ` ` ` ` `for` `i ` `in` `range` `(l ` `+` `1` `): ` ` ` ` ` `# substring representing int a ` ` ` `s ` `=` `N[` `0` `: ` `0` `+` `i] ` ` ` ` ` `# no of digits in a ` ` ` `l1 ` `=` `len` `(s) ` ` ` ` ` `# consider only most significant ` ` ` `# l1 characters of remaining ` ` ` `# string for int b ` ` ` `t ` `=` `N[i: l1 ` `+` `i] ` ` ` ` ` `# if any of a or b contains ` ` ` `# leading 0s discard this ` ` ` `try` `: ` ` ` `if` `s[` `0` `] ` `=` `=` `'0'` `or` `t[` `0` `] ` `=` `=` `'0'` `: ` ` ` `continue` ` ` `except` `: ` ` ` `continue` ` ` ` ` `# if both are equal ` ` ` `if` `s ` `=` `=` `t: ` ` ` `count` `+` `=` `1` ` ` `return` `count ` ` ` `# driver code to test above function ` `N ` `=` `str` `(` `"2202200"` `) ` `print` `(calculate(N)) ` ` ` `# This code is contributed by "Sharad_Bhardwaj". ` |

*chevron_right*

*filter_none*

## C#

`// C# program to count ways to divide a ` `// String in two parts a and b such that ` `// b/pow(10, p) == a ` `using` `System; ` ` ` `class` `GFG ` `{ ` `static` `int` `calculate(String N) ` `{ ` ` ` `int` `len = N.Length; ` ` ` `int` `l = (len) / 2; ` ` ` `int` `count = 0; ` ` ` ` ` `for` `(` `int` `i = 1; i <= l; i++) ` ` ` `{ ` ` ` ` ` `// subString representing int a ` ` ` `String s = N.Substring(0, i); ` ` ` ` ` `// no of digits in a ` ` ` `int` `l1 = s.Length; ` ` ` ` ` `// consider only most significant ` ` ` `// l1 characters of remaining String ` ` ` `// for int b ` ` ` `String t = N.Substring(i, l1); ` ` ` ` ` `// if any of a or b contains leading 0s ` ` ` `// discard this combination ` ` ` `if` `(s[0] == ` `'0'` `|| t[0] == ` `'0'` `) ` ` ` `continue` `; ` ` ` ` ` `// if both are equal ` ` ` `if` `(s.CompareTo(t) == 0) ` ` ` `count++; ` ` ` `} ` ` ` `return` `count; ` `} ` ` ` `// Driver Code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `String N = ` `"2202200"` `; ` ` ` `Console.Write(calculate(N)); ` `} ` `} ` ` ` `// This code is contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

**Output:**

2

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.

## Recommended Posts:

- Longest Even Length Substring such that Sum of First and Second Half is same
- First number to leave an odd remainder after repetitive division by 2
- Count number of rotated strings which have more number of vowels in the first half than second half
- Number of ways to split a binary number such that every part is divisible by 2
- Minimum number of sub-strings of a string such that all are power of 5
- Remove characters from the first string which are present in the second string
- Given two strings, find if first string is a subsequence of second
- Find the character in first string that is present at minimum index in second string
- Check whether second string can be formed from characters of first string
- Count subsequences in first string which are anagrams of the second string
- Interchanging first and second halves of stings
- Minimum changes required to make first string substring of second string
- Most frequent word in first String which is not present in second String
- Count of strings in the first array which are smaller than every string in the second array
- Count of times second string can be formed from the characters of first string
- Frequency of smallest character in first sentence less than that of second sentence
- Split the string into minimum parts such that each part is in the another string
- Minimum splits in a binary string such that every substring is a power of 4 or 6.
- DFA based division
- Program to compute division upto n decimal places

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.