-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path292C.cpp
107 lines (100 loc) · 2.57 KB
/
292C.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Rodrigo Farias de Macêdo
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define EACH(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define SZ(S) ((int) ((S).size()))
#define DEBUG(x) { cout << #x << " = " << x << endl; }
#define PR(a,n) { cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl; }
#define PR0(a,n) { REP(_,n) cout << a[_] << ' '; cout << endl; }
map<int, ll> fat;
int a, occurs[10];
ll total;
char number[17];
char ans[50];
void init(){
fat['0'] = 1;
fat['1'] = 1;
FOR(i, 2, 9){
char aux[10], aux2[10];
itoa(i,aux, 10);
itoa((i-1),aux2, 10);
fat[aux[0]] = fat[aux2[0]] * i;
}
}
void nayvePrimeFactors(){
REP(i, a){
if(number[i] == '2') occurs[2]++;
else if(number[i] == '3'){
occurs[2]++;
occurs[3]++;
}else if(number[i] == '4'){
occurs[2]+=3;
occurs[3]++;
}else if(number[i] == '5'){
occurs[2]+=3;
occurs[3]++;
occurs[5]++;
}else if(number[i] == '6'){
occurs[2]+=4;
occurs[3]+=2;
occurs[5]++;
}else if(number[i] == '7'){
occurs[2]+=4;
occurs[3]+=2;
occurs[5]++;
occurs[7]++;
}else if(number[i] == '8'){
occurs[2]+=7;
occurs[3]+=2;
occurs[5]++;
occurs[7]++;
}else if(number[i] == '9'){
occurs[2]+=7;
occurs[3]+=4;
occurs[5]++;
occurs[7]++;
}
}
}
void solve(){
int pos = 0;
while(occurs[2] > 0 || occurs[3] > 0 || occurs[5] > 0 || occurs[7] > 0 ){
if(occurs[7] > 0){
occurs[7]--;
occurs[5]--;
occurs[3]-=2;
occurs[2]-=4;
ans[pos] = '7';
pos++;
}else if(occurs[5] > 0){
occurs[5]--;
occurs[3]-=1;
occurs[2]-=3;
ans[pos] = '5';
pos++;
}else if(occurs[3] > 0){
occurs[3]-=1;
occurs[2]-=1;
ans[pos] = '3';
pos++;
}else if(occurs[2] > 0){
occurs[2]-=1;
ans[pos] = '2';
pos++;
}
}
REP(i, pos) cout << ans[i];
cout << endl;
}
int main() {
init();
cin >> a;
cin >> number;
nayvePrimeFactors();
solve();
return 0;
}