|It is well known that a number is divisible by 2 if and only if its rightmost digit is divisible by 2. A number is divisible by 3 if and only if the sum of its digits is divisible by 3. Assessing divisibility by 7 is a bit more complicated: starting from the rightmost digit, we multiply the first digit by 1, the second by 3, the third by 2, the fourth by 6, the fifth by 4, the sixth by 5, the seventh by 1, the eighth by 3 and so on ... Then, we sum up these results. The number thus obtained is divisible by 7 if and only if the initial number was divisible by 7.
In this problem, you will be given an int N representing the number of digits the number has, and a prime number P. Your task is to find a divisibility criterion for a number with N digits with a prime P. More specifically, you should assign a factor for each digit, such that their sum is divisible by P if and only if the N-digit number is divisible by P.
In order to ensure the uniqueness of the solution, we add the following restrictions:
- all the factors must be between 0 and P-1 inclusive.
- the factor for the rightmost digit should be 1.
- if the N-digit number has leading zeros, the returned factors should still work.
Return a int representing the factors assigned to each digit, starting with the leftmost digit.
|-||P is a prime number less than 100.|
|-||N is between 1 and 18, inclusive.|