37 lines
682 B
Python
37 lines
682 B
Python
import operator
|
|
from pprint import pprint
|
|
|
|
n, m, q = map(int, input().split())
|
|
|
|
nums = {}
|
|
for x in range(n):
|
|
for y in range(m):
|
|
if x == 0 and y == 0:
|
|
continue
|
|
s = (x / y) if y != 0 else float('inf')
|
|
nums.setdefault(s, []).append((x, y))
|
|
|
|
buckets = sorted(nums)
|
|
buckets = [nums[b] for b in buckets]
|
|
blens = []
|
|
blen = 0
|
|
for b in buckets:
|
|
blen += len(b)
|
|
blens.append(blen)
|
|
|
|
|
|
def find_bucket(i):
|
|
x = 0
|
|
while x < len(blens) - 1 and blens[x] <= i:
|
|
x += 1
|
|
|
|
return x, i - blens[x]
|
|
|
|
|
|
for _ in range(q):
|
|
i = int(input())-1
|
|
x, i = find_bucket(i)
|
|
buckets[x].sort()
|
|
a, b = buckets[x][i]
|
|
print(a + 1, b + 1)
|