-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProblem_#85_Counting_rectangles.cpp
More file actions
75 lines (68 loc) · 1.29 KB
/
Problem_#85_Counting_rectangles.cpp
File metadata and controls
75 lines (68 loc) · 1.29 KB
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
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<double, double> dd;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const int M = 2e3;
int main(){
map<int, int> memo;
for(int i=1;i<M;i++){
for(int j=1;j<M;j++){
ll t = i*(i+1);
t *= j*(j+1);
if(t > 1e8) continue;
t /= 4;
int x = t;
memo[x] = max(memo[x], i*j);
}
}
vii v(memo.begin(), memo.end());
/*for(int i=0;i<10;i++){
cout << v[i].first <<" "<<v[i].second << endl;
}*/
int t; cin >> t;
while(t--){
int n; cin >> n;
int a = 0, b = v.size()-1;
int res = -1;
while(a <= b){
int mid = (a+b)/2;
if(v[mid].first <= n){
a = mid+1;
}else{
res = mid;
b = mid-1;
}
}
int ans = -1;
if(v[res].first == n){
ans = v[res].second;
}else{
int bel = v[res-1].first;
int ab = v[res].first;
if(ab-n == n-bel){
ans = max(v[res].second, v[res-1].second);
}else if(ab-n < n-bel){
ans = v[res].second;
}else{
ans = v[res-1].second;
}
}
cout << ans << endl;
}
}