Anagrams divisible by 11
Time limit1sMemory limit128 MB
Count distinct digit permutations of N with no leading zero that are multiples of 11, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
A natural number can be written as a sequence of digits, and a sequence of digits can be read back as a natural number. A leading zero is not allowed. For example, gives the sequence , while the sequence represents no natural number.
An anagram of a sequence keeps the same elements and only changes their order. Anagrams of a natural number are defined the same way. The anagrams of are 2009, 2090, 2900, 9002, 9020, 9200.
Given a natural number , write a program that counts how many anagrams of are multiples of 11. For , only 2090 and 9020 are multiples of 11, so the answer is 2.
Input
The first line contains a natural number with no leading zero. ()
Output
Print how many anagrams of are multiples of 11. The answer can be very large, so print it modulo .