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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
| #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N;
vector<int> testcase;
vector<int> result;
int gcd(int a, int b){
if(a%b == 0){
return b;
}
return gcd(b, a%b);
}
void dfs(int num, int status){
if(status == (1<<N)-1){
result.push_back(num);
}
for(int i = 0; i<N; i++){
if(!(status & (1<<i))){
int next = num*10 + testcase[i];
dfs(next, status | (1<<i));
}
}
}
int main(){
scanf("%d", &N);
for(int i = 0; i<N; i++){
int tmp;
scanf("%d", &tmp);
testcase.push_back(tmp);
}
int K;
scanf("%d", &K);
for(int i = 0; i<N; i++){
dfs(testcase[i], (1<<i));
}
sort(result.begin(), result.end());
result.erase(unique(result.begin(), result.end()), result.end());
int cnt = 0;
for(int i = 0; i<result.size(); i++){
if(result[i]%K == 0){
cnt++;
}
}
if(cnt == 0){
printf("0/1\n");
}
else if(result.size() == cnt){
printf("1/1\n");
}
else{
int a = gcd((int)result.size(), cnt);
printf("%d/%d\n", cnt/a, (int)result.size()/a);
}
}
|