1701. Cannonball Pyramids

1701. Cannonball Pyramids

Description

If you visit historical battlegrounds from periods when cannon were used, you may see cannonballs (metal spheres) stacked in various ways. In this problem we're interested in the number of cannonballs in such pyramids with triangular bases -- that is, with cannonballs arranged in an equilateral triangle on the base, then similar equilateral triangles of cannonballs stacked on top of that, until a single cannonball is placed on the top. This three-sided pyramid is, in fact, one of the Platonic solids, a tetrahedron.

For example, suppose we begin with a base containing 6 cannonballs arranged in an equilateral triangle as shown in the figure on the left; this equilateral triangle has 3 cannonballs on each edge. The next layer will contain 3 cannonballs, 2 on each edge -- as shown in the middle. The final layer always contains just one cannonball. The total number of cannonballs in this pyramid is thus 6 + 3 + 1 = 10. In general, each layer of such a pyramid will have one fewer cannonballs on each edge of the triangle than the next lower layer.

The number of cannonballs in a layer is just the sum of the integers from 1 to N, where N is the number of cannonballs on one side of the layer.

Given the number of cannonballs on each side of the base, compute the total number of cannonballs in the entire tetrahedral pyramid.

Input

The first line of the input contains a single integer N giving the number of cases posed, for a maximum of 100 cases. Following that are exactly N lines, each with a single integer giving the number of cannonballs on each side of the base for a tetrahedron of cannonballs, a number less than 1000.

Output

For each input case, display the case number (1, 2, ...), a colon and a blank, the number of cannonballs on each side of the base, one blank, and finally the total number of cannonballs in the tetrahedron.

Sample Input

5
3
5
27
999
1

Sample Output

1: 3 10
2: 5 35
3: 27 3654
4: 999 166666500
5: 1 1


#include <iostream>
using namespace std;
int main()
{
	int t;
	cin>>t;
	for(int k=1;k<=t;k++)
	{
		int n,t=0;
		cin>>n;
		long sum=0;
		for(int i=1;i<=n;i++)
		{
			t+=i;
			sum+=t;
		}
		cout<<k<<": "<<n<<" "<<sum<<endl;
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值