View Code of Problem 3698

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main(void)
{
    int n;
    cin >> n;
    while (n--)
    {
        long long tmp;
        cin >> tmp;
        long long heap = 1, sum = 1;
        while (tmp > sum)
        {
            tmp -= sum;
            heap++;
            sum += heap;
        }
        long long row = 1;
        while (tmp > row)
        {
            tmp -= row;
            row++;
        }
        cout << heap << " " << row << " " << tmp << endl;
    }
}

Double click to view unformatted code.


Back to problem 3698