LightOJ 1008 Fibsieve`s Fantabulous Birthday

来源:互联网 发布:淘宝假冒商品申诉材料 编辑:程序博客网 时间:2024/05/07 16:33

Description

Fibsieve had a fantabulous (yes, it's an actual word) birthday party this year. He had so many gifts that he was actually thinking of not having a party next year.

Among these gifts there was an N x N glass chessboard that had a light in each of its cells. When the board was turned on a distinct cell would light up every second, and then go dark.

The cells would light up in the sequence shown in the diagram. Each cell is marked with the second in which it would light up.

(The numbers in the grids stand for the time when the corresponding cell lights up)

In the first second the light at cell (1, 1) would be on. And in the 5th second the cell (3, 1) would be on. Now, Fibsieve is trying to predict which cell will light up at a certain time (given in seconds). Assume that N is large enough.

Input

Input starts with an integer T (≤ 200), denoting the number of test cases.

Each case will contain an integer S (1 ≤ S ≤ 1015) which stands for the time.

Output

For each case you have to print the case number and two numbers (x, y), the column and the row number.

Sample Input

3

8

20

25

Sample Output

Case 1: 2 3

Case 2: 5 4

Case 3: 1 5


#include <stdio.h>#include <math.h>int main(){    int t,x,y,cas=0;    long long s,n,num;    scanf("%d",&t);    while(t--)    {        scanf("%lld",&s);        n=sqrt(s);        if(s>(n*n))            n++;        num=n*n-(n-1);        if(n%2==1)        {            if(s>num)            {                x=n-(s-num);                y=n;            }            else            {                y=n-(num-s);                x=n;            }        }        else        {            if(s>num)            {                y=n-(s-num);                x=n;            }            else            {                x=n-(num-s);                y=n;            }        }        printf("Case %d: %d %d\n",++cas,x,y);    }    return 0;}


0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 摩托车驾驶证年审过期一个月怎么办 摩托车驾驶证记满12分怎么办 b2驾驶证扣2分该怎么办 b2扣6分以上怎么办 审驾照晚了3天怎么办 考驾驶证3年到期怎么办 学习驾驶证明过期了怎么办 a2扣了12分怎么办 驾照a2扣6分了怎么办 a2本扣9分怎么办 驾驶证分扣3分怎么办? 异地换驾驶证没有居住证怎么办 b2开c1车扣分怎么办 驾照五次没考过怎么办 大车行驶证丢了怎么办 车的产权证丢了怎么办 车子行驶证掉了怎么办 定期的存折丢了怎么办 存折密码输错6次怎么办 营业执照原件丢失怎么办怎么注销 违章扣了14分怎么办 c1驾驶本过期了怎么办 考驾照没带身份证怎么办 上海扣满12分怎么办 美宝旅行证丢失怎么办 汽车证件全丢了怎么办 车的行驶本丢了怎么办 车和行驶证丢了怎么办 考驾照人在外地怎么办 外地考驾照没有居住证怎么办 考驾驶证预约密码忘了怎么办 考驾照密码忘了怎么办 考驾照的密码忘了怎么办 手机银行登录密码忘了怎么办 宽带账号或密码错误怎么办 车险过户联系不上原车主怎么办 换车了etc忘拆了怎么办 c1d驾驶证d证到期了怎么办 摩托车驾驶证过五年怎么办 没居住证想上东莞牌怎么办 外地考驾照需要暂住证怎么办