Access:

» TopCoder Problem: Divisible Permutations

Related categories:

Andrew Lazarev
Viewed: 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 author

Andrew_Lazarev is the number 35th - ranked TopCoder member. He is a student at Saratov State Socio-Economic University in the Russian Federation.

Definition

  • Class: DivisiblePermutations

  • Method: count

  • Parameters: String, int

  • Returns: long

  • Method signature: long count(String N, int M)

(be sure your method is public)

Constraints

N will contain between 1 and 15 non-zero digits ('1'-'9'), inclusive.

M will be between 1 and 50, inclusive.

Examples

Example 0) There are three permutations of 133 (133, 313, 331), but only 133 is divisible by 7.

  • "133"

  • 7

  • Returns: 1

Example1) The permutations of 2753 that are divisible by 5 are 2375, 2735, 3275, 3725, 7235 and 7325.

  • "2753"

  • 5

  • Returns: 6

Example 2)

  • "1112225"

  • 5

  • Returns: 20

Example 3)

  • "123456789"

  • 17

  • Returns: 21271

Example 4)

  • "987654321999999"

  • 39

  • Returns: 19960896

A d v e r t i s e m e n t
Linux BSD Unix ranking vote

Page: 1 2
Buy article Buy subscription
Buy now add to cart
add to cart
Standard price: 2€/$3 Standard price: 25€/$30
Buy article for as little as (2€/$3) each allow access to individual articles. Buy a full access to our Software Developers's Journal archive portal. You will be able to read the articles from all archive issues from year 2005 and 2006. For just 25€/$30 you get unrestricted access to the entire website for the whole year.
SDJhakin9

.SDJ Users:


.:Login
.:Password

[Register]
[Forgotten your password?]

...Shopping Cart

sum: 0 €
Choose currency:

...Topics

...Advertisement

www.acunetix.com www.verifysoft.com

...Conferences




...Print Edition Archive

...Affiliate Program



 

 

Subscribe | Contact Us | Newsletter | Privacy policy | Regulations | See all issues | About SDJ
Copyright C 2006 by Software Developer's Journal. All rights reserved.