Shakti and Challenge

0

0 votes
Medium, Medium
Problem

Shakti is one enthusiastic coder. One day he was challenged by Param for a duel. For the competition to be fair Princu the prince decided to prepare a question for them. The questions is to find how many numbers are doppelganger for a pair of numbers N and M. For a given pair of numbers N and M, a number x is doppelganger if all three conditions hold for x -

1) it can be obtained by rearranging the digits of number N,

2) it doesn't have any leading zeroes,

3) the remainder after dividing number x by M equals 0.

You are on Shakti's side. Help him win the duel by finding the total number of doppelganger for the pair of N and M.

INPUT

The only line contains two integers N and M.

OUTPUT

Print the total number of integers that are doppelganger for the given pair of N and M.

CONSTRAINTS

1 <= N <= 10^18

1 <= m <= 100

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?