forked from anandadfoxx/codeforces_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1345B.cpp
42 lines (36 loc) · 875 Bytes
/
1345B.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
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int find(int* arr, int val) {
int l = 1, r = 30000;
while (l <= r) {
int m = (l + r) / 2;
if (l != r) {
if (val > arr[m] && arr[m+1] <= val) l = m + 1;
else if (val < arr[m]) r = m - 1;
else return m;
} else return m;
}
return 0;
}
int main() {
int t;
cin >> t;
int dp[30001];
// COMPUTE DP
dp[1] = 2;
FOR(i, 2, 30001) dp[i] = dp[i-1] + (3 * i) - 1;
while (t--) {
int x, ans = 0;
cin >> x;
while (x > 1) {
int idx = find(dp, x),
tmp = x / dp[idx];
// cout << idx << ' ';
ans += tmp;
x -= tmp * dp[idx];
}
cout << ans << '\n';
}
}