View Code of Problem 3698

#include<iostream>
#include<cstdio>

using namespace std;
long long a[1000000];

int main()
{
	int tc;
	long long n;
	long long x, y, z;
	long long d = 1;
	cin >> tc;
	a[0] = 1;
	for(int i = 1; i < 1000000; i++)
	{
		d += i + 1;
		a[i] = d;
	}
	
	while(tc--)
	{
		cin >> n;
		int i;
		for(i = 0; n > a[i]; i++)
			n -= a[i];
		x = i + 1;
		
		for(i = 0; n > i + 1; i++)
			n -= i + 1;
		y = i + 1;
		z = n;
		cout << x << ' ' << y << ' ' << z << endl;
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 3698