-
Notifications
You must be signed in to change notification settings - Fork 0
/
d17-test.py
248 lines (198 loc) · 4.93 KB
/
d17-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# # MUH and Important Things
# N = int(input())
# h = list(map(int, input().split()))
# h_dict = dict()
# h_count = dict()
# for i in range(N):
# h_dict[i + 1] = h[i]
# h_dict_sorted = sorted(h_dict.items(), key=lambda kv: kv[1])
# for i in range(N):
# if h[i] not in h_count:
# h_count[h[i]] = 1
# else:
# h_count[h[i]] += 1
# h_count_sorted = sorted(h_count.items(), key=lambda kv: kv[1])
# total = 0
# can_swap = []
# for (key, value) in h_count_sorted:
# if total >= 3:
# break
# if value >= 2:
# can_swap.append((key, value))
# total += value
# def print_result_list(current_l, c_swap):
# global max_print
# new_list = current_l
# c_key, c_value = c_swap
# count_swap = 0
# for i in range(len(current_l)):
# current_l_key, current_l_value = current_l[i]
# if max_print == 3:
# break
# if count_swap < c_value - 1 and c_key == current_l_value:
# new_list[i], new_list[i + 1] = new_list[i + 1], new_list[i]
# count_swap += 1
# max_print += 1
# print(' '.join([str(key) for (key, value) in new_list]))
# max_print = 1
# if total < 3:
# print('NO')
# else:
# print('YES')
# print(' '.join([str(key) for (key, value) in h_dict_sorted]))
# print_result_list(h_dict_sorted, can_swap[0])
# if len(can_swap) > 1:
# print_result_list(h_dict_sorted, can_swap[1])
# Fibsieve Fantabulous
import math
T = int(input())
for case in range(T):
S = int(input())
N = 0
x = 0
y = 0
ceil_i = math.ceil(S ** 0.5)
N = ceil_i
number_of_move = abs(S - (N - 1) ** 2)
if N % 2 == 1:
if number_of_move < N:
x = N
y = number_of_move
else:
y = N
x = N - (number_of_move - N)
else:
if number_of_move < N:
y = N
x = number_of_move
else:
x = N
y = N - (number_of_move - N)
print('Case {}: {} {}'.format(case + 1, x, y))
# Ubiquitous Religions
# parent = []
# ranks = []
# def make_set(n):
# global parent, ranks
# parent = [i for i in range(n + 1)]
# ranks = [i for i in range(n + 1)]
# def find_set(u):
# global parent
# if parent[u] != u:
# parent[u] = find_set(parent[u])
# return parent[u]
# def union_set(u, v):
# global parent, ranks
# up = find_set(u)
# vp = find_set(v)
# if up == vp:
# return
# if ranks[up] > ranks[vp]:
# parent[vp] = up
# elif ranks[up] < ranks[vp]:
# parent[up] = vp
# else:
# parent[up] = vp
# ranks[vp] += 1
# case = 0
# while True:
# N, M = list(map(int, input().split()))
# if N == 0 and M == 0:
# break
# case += 1
# result = N
# make_set(N)
# for _ in range(M):
# i, j = list(map(int, input().split()))
# u = find_set(i)
# v = find_set(j)
# if u != v:
# result -= 1
# union_set(i, j)
# print('Case {}: {}'.format(case, result))
# Phone List
# class Node:
# def __init__(self):
# self.count_word = 0
# self.child = dict()
# def add_word(root, s):
# tmp = root
# for i in range(len(s)):
# ch = s[i]
# if ch not in tmp.child:
# tmp.child[ch] = Node()
# else:
# if tmp.child[ch].count_word >= 1 and i <= len(s) - 1:
# return False
# tmp = tmp.child[ch]
# tmp.count_word += 1
# if len(tmp.child) > 0:
# return False
# return True
# T = int(input())
# for case in range(T):
# N = int(input())
# root = Node()
# result = True
# phone_numbers = []
# for i in range(N):
# number = input()
# phone_numbers.append(number)
# for number in phone_numbers:
# result = add_word(root, number)
# if result == False:
# break
# final_res = 'YES' if result == True else 'NO'
# print(final_res)
# # Freckles
# from heapq import heappush, heappop
# INF = 1e9
# def distance(A, B):
# x, y = A
# z, t = B
# return ((x - z) ** 2 + (y - t) ** 2)
# def prim(src):
# global min_heap, graph, dist, path, visited
# dist[src] = 0
# heappush(min_heap, (dist[src], src))
# while len(min_heap) != 0:
# top = heappop(min_heap)
# u = top[1]
# if visited[u]:
# continue
# visited[u] = True
# for (w, v) in graph[u]:
# if visited[v] == False and w < dist[v]:
# dist[v] = w
# path[v] = u
# heappush(min_heap, (w, v))
# def print_dist():
# res = 0
# for i in range(1, N):
# if path[i] == -1:
# continue
# res = res + dist[i] ** 0.5
# print('{:.2f}'.format(res))
# T = int(input())
# for case in range(T):
# input()
# N = int(input())
# min_heap = []
# graph = [[] for i in range(N)]
# dist = [INF for i in range(N)]
# path = [-1 for i in range(N)]
# visited = [False for i in range(N)]
# points = []
# for _ in range(N):
# x, y = list(map(float, input().split()))
# points.append((x, y))
# for i in range(N):
# for j in range(i, N):
# w = distance(points[i], points[j])
# if i != j:
# graph[i].append((w, j))
# graph[j].append((w, i))
# prim(0)
# print_dist()
# if case != T - 1:
# print()