#include <bits/stdc++.h>
#include "mpi.h"
using namespace std;
void solve(long long n, long long &cnt) {
cnt = 0;
while (n > 2) {
long long step = 5;
long long current_sum = 2;
while (n >= current_sum + step) {
current_sum += step;
step += 3;
}
n -= current_sum;
cnt++;
}
if (n >= 2) {
cnt++;
}
}
int main(int argc, char *argv[]) {
MPI_Init(&argc, &argv);
int rank, size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
int testcases;
if (rank == 0) {
cin >> testcases;
}
MPI_Bcast(&testcases, 1, MPI_INT, 0, MPI_COMM_WORLD);
int cases_per_process = testcases / size;
int start_index = rank * cases_per_process;
int end_index = (rank == size - 1) ? testcases : (rank + 1) * cases_per_process;
vector<long long> results(end_index - start_index);
for (int i = start_index; i < end_index; ++i) {
long long n;
cin >> n;
solve(n, results[i - start_index]);
}
vector<long long> all_results(testcases);
MPI_Gather(results.data(), cases_per_process, MPI_LONG_LONG,
all_results.data(), cases_per_process, MPI_LONG_LONG,
0, MPI_COMM_WORLD);
if (rank == 0) {
for (int i = 0; i < testcases; ++i) {
cout << all_results[i] << endl;
}
}
MPI_Finalize();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlICJtcGkuaCIKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZvaWQgc29sdmUobG9uZyBsb25nIG4sIGxvbmcgbG9uZyAmY250KSB7CiAgICBjbnQgPSAwOwogICAgd2hpbGUgKG4gPiAyKSB7CiAgICAgICAgbG9uZyBsb25nIHN0ZXAgPSA1OwogICAgICAgIGxvbmcgbG9uZyBjdXJyZW50X3N1bSA9IDI7CiAgICAgICAgd2hpbGUgKG4gPj0gY3VycmVudF9zdW0gKyBzdGVwKSB7CiAgICAgICAgICAgIGN1cnJlbnRfc3VtICs9IHN0ZXA7CiAgICAgICAgICAgIHN0ZXAgKz0gMzsKICAgICAgICB9CiAgICAgICAgbiAtPSBjdXJyZW50X3N1bTsKICA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