define S ,it is sum of all possible permutations
of a given set of digits. For example, if the digits are <1 2 3>, then six possible permutations are
<123>, <132>, <213>, <231>, <312>, <321> and the sum of them is 1332.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define int unsigned long long
int n,S,a[50],cnt[50] ;
const int R[] = {0,1,11,111,1111,11111,111111,
1111111,11111111,111111111,1111111111,11111111111,111111111111};
int F(int x){
if(x==0) return 1;
int r=1;
for(int i=2;i<=x;i++) r*=i;
return r;
}
signed main(){
int i;
while(cin>>n && n){
memset(cnt,0,sizeof cnt) ;
int ans=S=0;
for(i=1;i<=n;i++){
cin>>a[i]; ++cnt[a[i]]; S+=a[i];
}
int k=F(n) ;
for(i=0;i<=9;i++) k/= F(cnt[i]);
cout<<(k*S*R[n])/n<<endl;
}
}
浙公网安备 33010602011771号