Problem Statement
Sometimes it is possible to rearrange the digits of a positive integer to get a different positive integer that is a multiple of the original number.
For example, the number x = 142857 does have this property if we use base 10.
In base 10 we can rearrange the digits of x to get the number 285714, and we have 285714 = 2 * 142857.
(Note that adding leading zeros to the original number is not allowed. For example, it is not allowed to write the number 7 as 007 and then to rearrange those digits to get 700.)
You are given the ints L and b. Your task is to construct a positive integer x with the following properties:
In order to return a positive integer x, do the following:
(Note that adding leading zeros to the original number is not allowed. For example, it is not allowed to write the number 7 as 007 and then to rearrange those digits to get 700.)
You are given the ints L and b. Your task is to construct a positive integer x with the following properties:
- When written in base b, the integer x has exactly L digits.
- We can rearrange the base-b digits of x to get a different L-digit number that is a multiple of x.
In order to return a positive integer x, do the following:
- Take each of its base-b digits separately.
- Write the value of that digit in base 10.
- Return a String that contains all those values separated by single spaces.
Definition
- Class:
- RearrangeAndMultiple
- Method:
- construct
- Parameters:
- int, int
- Returns:
- String
- Method signature:
- String construct(int b, int L)
- (be sure your method is public)
Constraints
- b will be between 2 and 100,000, inclusive.
- L will be between 1 and 100, inclusive.
Examples
10
6
Returns: "1 4 2 8 5 7"
We can rearrange 142857 into 284714 which is 2 * 142857. Note that we can also rearrange it into 428571 = 3 * 142857 as well.10
4
Returns: "1 0 3 5"
3105 = 1035 * 310
14
Returns: "1 4 2 8 5 7 1 0 3 5 1 0 3 5"
42857131053105 = 3 * 1428571035103516
5
Returns: "7 11 13 14 15"
F7BDE = 2 * 7BDEF.1234
2
Returns: "246 987"
2
97
Returns: ""