Search:
|
Access:
» TopCoder Problem: Divisible PermutationsRelated categories: Andrew LazarevViewed: 1325 | Article date: 2006-05-13 17:38:21 To define a permutation of an integer N as an integer that has the exact same digits as N, but possibly in a different order.
We define a permutation of an integer N as an integer that has the exact same digits as N, but possibly in a different order. Two permutations of N are considered different if the numbers they represent are not the same. For example, the set of all different permutations of the number N = 313 is {133, 313, 331}. Given a String N and an int M, determine the number of different permutations of N that are divisible by M.
About the authorAndrew_Lazarev is the number 35th - ranked TopCoder member. He is a student at Saratov State Socio-Economic University in the Russian Federation. Definition
(be sure your method is public) ConstraintsN will contain between 1 and 15 non-zero digits ('1'-'9'), inclusive. M will be between 1 and 50, inclusive. ExamplesExample 0) There are three permutations of 133 (133, 313, 331), but only 133 is divisible by 7.
Example1) The permutations of 2753 that are divisible by 5 are 2375, 2735, 3275, 3725, 7235 and 7325.
Example 2)
Example 3)
Example 4)
|
|
Copyright C 2006 by Software Developer's Journal. All rights reserved.






SDJ Users:
Shopping Cart









