Connection Status:
Competition Arena > Permutiple
SRM 716 · 2017-05-20 · by cgy4ever · Brute Force
Class Name: Permutiple
Return Type: String
Method Name: isPossible
Arg Types: (int)
Problem Statement

Problem Statement

You are given a positive integer x. Please check whether we can rearrange the digits of x (in base 10, without leading zeros) to produce a different number that is a multiple of x.

Return "Possible" if this can be done and "Impossible" otherwise. Note that the return value is case-sensitive.

Constraints

  • x will be between 1 and 1,000,000, inclusive.
Examples
0)
142857
Returns: "Possible"

One valid way of rearranging the digits of 142857 is to form the number 285714. This new number is a multiple of x: we have 285714 = 2 * 142857. Another valid way is to form the number 857142 (which is equal to 6 * 142857).

1)
14
Returns: "Impossible"

The only other number we can get by rearranging the digits of the number 14 is the number 41. As 41 is not a multiple of 14, there is no solution.

2)
1035
Returns: "Possible"

We can get 3105 = 3 * 1035.

3)
1000000
Returns: "Impossible"
4)
100035
Returns: "Possible"

Submissions are judged against all 108 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class Permutiple with a public method string isPossible(int x) · 108 test cases · 2 s / 256 MB per case

Submitting as anonymous