forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path88.cpp
More file actions
56 lines (46 loc) · 951 Bytes
/
88.cpp
File metadata and controls
56 lines (46 loc) · 951 Bytes
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
#include <iostream>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define MAXN 12000
#define INF 1000000000
int mul, sum, idx;
int mm[MAXN + 5];
void go(int n) {
int dest = mul - sum + idx;
if (dest > MAXN) return;
mm[dest] = min(mm[dest], mul);
FOR(i,n,MAXN) {
mul *= i, sum += i, ++idx;
if (mul - sum + idx <= MAXN) go(i);
mul /= i, sum -= i, --idx;
}
}
set<int> dd;
void run() {
FOR(i,2,MAXN) mm[i] = INF;
FOR(i,2,MAXN) {
//cout << i << endl;
mul = i, sum = i, idx = 1;
go(i);
}
dd.clear();
FOR(i,2,MAXN) {
//cout << i << " " << mm[i] << endl;
dd.insert(mm[i]);
}
int res = 0;
for (set<int>::iterator itr = dd.begin(); itr != dd.end(); ++itr) res += *itr;
cout << res << endl;
}
int main () {
run();
return 0;
}