Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- #include <cmath>
- using namespace std;
- int main()
- {
- int t_case, t = 1;
- cin >> t_case;
- long long int col, row, max, min, mid, temp,num;
- while(t_case--)
- {
- cin >> num;
- if(num == 1)
- {
- printf("Case %d: ", t++);
- cout << 1 << ' ' << 1 << endl;
- }
- else
- {
- temp = ceil(sqrt(num));
- max = temp*temp;
- min = (max - ((temp*2) - 2));
- mid = (max+min) / 2;
- if(!(max & 1))
- {
- if(num < mid)
- {
- col = (num - min)+1;
- row = temp;
- }
- else if(num > mid)
- {
- col = temp;
- row = (max - num)+1;
- }
- else
- {
- col = row = temp;
- }
- }
- else
- {
- if(num < mid)
- {
- row = (num - min)+1;
- col = temp;
- }
- else if(num > mid)
- {
- row = temp;
- col = (max - num)+1;
- }
- else
- {
- col = row = temp;
- }
- }
- printf("Case %d: %lld %lld\n", t++, col, row);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement