TopcoderArchive
Archive
Algorithm problem

PermutationSum

Problem statement, definition, constraints, and public examples.

Problem Statement

We define a permutation of an integer n as an integer that has the same digits as n, but in an arbitrary order. Two permutations of n are considered different if the numbers they represent are not the same. For instance, the set of all possible permutations of the number n = 313 is: {133, 313, 331}.

Given an int n, your task is to find the sum of all its permutations.

Definition

Class:
PermutationSum
Method:
add
Parameters:
int
Returns:
int
Method signature:
int add(int n)
(be sure your method is public)

Constraints

  • n is between 1 and 99999, inclusive.
  • No digits of n are zero.

Examples

  1. 157
    Returns: 2886
    We have: 157 + 175 + 517 + 571 + 715 + 751 = 2886
  2. 313
    Returns: 777
    We have: 133 + 313 + 331 = 777
  3. 1234
    Returns: 66660
  4. 5
    Returns: 5
  5. 54321
    Returns: 3999960
  6. 99999
    Returns: 99999
Back to all problems