Shell Pyramid

Shell Pyramid

Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
Total Submission(s) : 14   Accepted Submission(s) : 0
Font: Times New Roman | Verdana | Georgia
Font Size: ← →

Problem Description

In the 17th century, with thunderous noise, dense smoke and blazing fire, battles on the sea were just the same as those in the modern times. But at that time, the cannon ,were extremely simple. It was just like an iron cylinder, with its rearward end sealed and forward end open. There was a small hole at the rearward end of it, which was used to install the fuse. The cannons on the warships were put on small vehicles which had four wheels and the shells were iron spheres with gunpowder in them.

At that time, it was said that there was an intelligent captain, who was also a mathematician amateur. He liked to connect everything him met to mathematics. Before every battle, he often ordered the soldiers to put the shells on the deck and make those shells to form shell pyramids.

Now let's suppose that a shell pyramid has four layers, and there will be a sequence of ordinal numbers in every layer. They are as the following figure:



In the figure, they are the first layer, the second layer, the third layer and the fourth layer respectively from the left to the right.

In the first layer, there is just 1 shell, and its ordinal number is 1. In the second layer, there are 3 shells, and their ordinal numbers are 1, 2, and 3. In the third layer, there are 6 shells, and their ordinal numbers are 1, 2, 3, 4, 5, and 6. In the fourth layer, there are 10 shells, and their ordinal numbers are shown in the figure above.

There are also serial numbers for the whole shell pyramid. For example, the serial number for the third shell in the second layer is 4, the serial number for the fifth shell in the third layer is 9, and the serial number for the ninth shell in the fourth layer is 19.

There is also a interrelated problem: If given one serial number s, then we can work out the s th shell is in what layer, what row and what column. Assume that the layer number is i, the row number is j and the column number is k, therefore, if s=19, then i=4, j=4 and k=3.

Now let us continue to tell about the story about the captain.
A battle was going to begin. The captain allotted the same amount of shells to every cannon. The shells were piled on the deck which formed the same shell pyramids by the cannon. While the enemy warships were near, the captain ordered to fire simultaneously. Thunderous sound then was heard. The captain listened carefully, then he knew that how many shells were used and how many were left.

At the end of the battle, the captain won. During the break, he asked his subordinate a question: For a shell pyramid, if given the serial number s, how do you calculate the layer number i, the row number j and column number k?

Input

First input a number n,repersent n cases.For each case there a shell pyramid which is big enough, a integer is given, and this integer is the serial number s(s<2^63). There are several test cases. Input is terminated by the end of file.

Output

For each case, output the corresponding layer number i, row number j and column number k.

Sample Input

2
19
75822050528572544

Sample Output

4 4 3
769099 111570 11179

Source

2008 Asia Regional Harbin

不知为何老是超时,,,还需要进一步解决啊.......最近状态很不好,,没有什么自信心了。。。。刚要进入大二,,眼看的网络赛就要到来了,,看来只能是去打酱油的了。
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    int n;
    int temp;
    int kk;
    __int64 m,sum,num,i,j,t;
    scanf("%d",&n);
    for(kk=1;kk<=n;kk++)
    {
        temp=-1;
        sum=0;
        num=0;
        scanf("%I64d",&m);
        j=0;
        for(i=1;;i++)
        {
            sum=sum+i;
            num=(i-1)*(i*i+i*4+6)/6+1;;
            if(num>=m)
            {
                num=num-sum;
                num=m-num;
                for(j=1;;j++)
                {
                    if(j*(j+1)/2>=num)
                        break;
                }
                t=j-(j*(j+1)/2-num);
                printf("%I64d %I64d %I64d\n",i,j,t);
                break;
            }
        }
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值