-
Notifications
You must be signed in to change notification settings - Fork 0
/
p10338.cpp
54 lines (52 loc) · 1.27 KB
/
p10338.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define sf scanf
#define pf printf
int main()
{
unsigned long long int t, i, j, k, l, m, n, count[20], len, total[20], fact, flag, value;
char ch[22], c;
sf("%llu", &t);
getchar();
for(i=1; i<=t; i++) {
for(j=0; j<20; j++) {
count[j] = 0;
total[j] = 1;
}
sf("%s", &ch);
len = strlen(ch);
sort(ch, ch+len);
ch[len] = ':';
ch[len+1] = '\0';
c = ch[0];
for(j=0, k=0; ch[j]; j++) {
if(c==ch[j]) {
count[k]++;
}else {
k++;
c = ch[j];
j--;
}
}
total[0] = 1;
for(j=0, m=0; j<k; j++) {
fact = 1;
for(l=1; l<=count[j]; l++) {
fact*=l;
}
total[m++]*=fact;
}
for(j=2, value=1, flag=0, n=0; j<=len; j++) {
value*=j;
if(value%total[n]==0 && flag<=m) {
value/=total[n];
flag++;
n++;
}
}
pf("Data set %llu: %llu\n", i, value);
}
}