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.
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
157
Returns: 2886
We have: 157 + 175 + 517 + 571 + 715 + 751 = 2886313
Returns: 777
We have: 133 + 313 + 331 = 7771234
Returns: 66660
5
Returns: 5
54321
Returns: 3999960
99999
Returns: 99999