-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCC-1345B.cpp
More file actions
58 lines (55 loc) · 1.29 KB
/
CC-1345B.cpp
File metadata and controls
58 lines (55 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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define nl "\n"
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(x) ll x; cin>>x; while(x--)
void shammi() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
shammi();
ll cards[10001] = {0};
for (ll i = 1; i <= 10000; i++) {
cards[i] = (i * (3 * i + 1)) / 2;
}
// 2 7 15 16 ....
w(t) {
ll n; cin >> n;
ll h = 0, rem, tri = 0;
if (n > 1) {
bool done = false;
for (ll i = 1; i <= 10000; i++) {
if (cards[i] > n) {
done = true;
h += (n / cards[i - 1]);
// tri += (h * (h + 1)) / 2; // answer
rem = n % cards[i - 1];
ll j = 1;
while (rem > 1) {
if (cards[j] > rem) {
h += rem / cards[j - 1];
// tri += (h * (h + 1)) / 2;
rem = rem % cards[j - 1];
j = 1;
continue;
} else j++;
}
break;
} else continue;
// if (done) break;
}
cout << h << nl;
} else cout << 0 << nl;
}
return 0;
}