LightOJ 1008 - Fibsieve`s Fantabulous Birthday
//Next Codeforces Round #354 (Div. 2)
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
//#define i64 long long
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
int main()
{
fast;
int t , tc=0;
LL s , m , n , k, col, row;
cin >> t;
while(t--)
{
cin >> s;
n = ceil(sqrt(s));
m = n*n;
k = m - n + 1; // find the sequence 1 , 3, 7, 13, 21
cout << "Case " << ++tc << ": ";
if(!(n&1))
{
if(s > k)
{
col = n;
row = k + n - s;
}
else
{
col = s - k + n;
row = n;
}
cout << col << " " << row << "\n";
}
else
{
if(s > k)
{
col = k + n - s;
row = n;
}
else
{
col = n;
row = s - k + n;
}
cout << col << " " << row << "\n";
}
}
return 0;
}
#include<bits/stdc++.h>
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
using namespace std;
#define fast ios_base::sync_with_stdio(false)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
//#define i64 long long
typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
int main()
{
fast;
int t , tc=0;
LL s , m , n , k, col, row;
cin >> t;
while(t--)
{
cin >> s;
n = ceil(sqrt(s));
m = n*n;
k = m - n + 1; // find the sequence 1 , 3, 7, 13, 21
cout << "Case " << ++tc << ": ";
if(!(n&1))
{
if(s > k)
{
col = n;
row = k + n - s;
}
else
{
col = s - k + n;
row = n;
}
cout << col << " " << row << "\n";
}
else
{
if(s > k)
{
col = k + n - s;
row = n;
}
else
{
col = n;
row = s - k + n;
}
cout << col << " " << row << "\n";
}
}
return 0;
}
Comments
Post a Comment