forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path85.cpp
More file actions
45 lines (39 loc) · 854 Bytes
/
85.cpp
File metadata and controls
45 lines (39 loc) · 854 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
#include <iostream>
using namespace std;
#define DEST 2000000
typedef long long LL;
LL doit(LL width, LL len) {
LL ret = 0;
for (LL i = 1; i <= len; ++i) {
for (LL j = 1; j <= width; ++j) {
ret += (len - i + 1) * (width - j + 1);
}
}
return ret;
}
void run() {
LL diff = DEST, area = DEST;
for (LL i = 1; ; ++i) {
bool flag = true;
for (LL j = i; ; ++j) {
LL temp = doit(i, j);
LL t = temp - DEST;
if (t < 0) t *= -1;
if (t < diff) {
diff = t;
area = i * j;
}
if (temp > DEST) {
break;
} else {
flag = false;
}
}
if (flag) break;
}
cout << area << endl;
}
int main() {
run();
return 0;
}