Fibsieve`s Fantabulous Birthday LightOJ - 1008(找规律。。)

时间:2023-03-09 06:06:39
Fibsieve`s Fantabulous Birthday LightOJ - 1008(找规律。。)

Description

某只同学在生日宴上得到了一个N×N玻璃棋盘,每个单元格都有灯。每一秒钟棋盘会有一个单元格被点亮然后熄灭。棋盘中的单元格将以图中所示的顺序点亮。每个单元格上标记的是它在第几秒被点亮。

Fibsieve`s Fantabulous Birthday LightOJ - 1008(找规律。。)

第一秒棋格(1,1)将被点亮,第五秒棋格(3,1)将被点亮。

现在这只同学想知道在给定的时间哪个棋格将被点亮(时间将以秒为单位给出)。题目假设N足够大。

Input

先输入一个整数T(<= 200) , 表示测试用例的组数。

每一组用例将包括一个整数S(1 ≤ S ≤ 1015),表示时间。

(注:此题中长整形的输入输出要用 %lld 格式实现)

Output

对于每组用例您必须打印用例编号和两个数字(x,y)表示列号和行号。

Sample Input

3

8

20

25

Sample Output

Case 1: 2 3

Case 2: 5 4

Case 3: 1 5

呃。。。找找规律。。。丫丫卡卡

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#define rap(a, n) for(int i=1; i<=n; i++)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff; int main()
{
int T, kase = ;
cin>> T;
while(T--)
{
LL s, x, m;
cin>> s;
m = ceil(sqrt((double)s)); x = m*m - s + ;
if(x == m)
printf("Case %d: %lld %lld\n", ++kase, m, m);
else if(x < m)
{
if((m*m) & )
printf("Case %d: %lld %lld\n", ++kase, x, m);
else
printf("Case %d: %lld %lld\n", ++kase, m, x);
}
else
{
if((m*m) & )
printf("Case %d: %lld %lld\n", ++kase, m, (*m - x));
else
printf("Case %d: %lld %lld\n", ++kase, (*m - x), m);
} } return ;
}