谷评:紫 自评:橙
ImmatureDreamer · · 题解
我做过的难度最低紫题。
由于数值很大,直接枚举是不行的。考虑根据当前的解推一组另外的解,这样可以方便地拓展。
假设可以通过解
将等式化为关于
根据韦达定理:
有之前的一个解
因此,我们可以推出的一组新解为
因为最多
k, n = map(int, input().split())
roots = {0}
p = 0
que = [(1, k, k * (k + 1))]
while 1:
a, b, c = que[p]
if a < 0 or b < 0 or c < 0:
break
p += 1
if a not in roots and b not in roots and c not in roots:
print(a, b, c)
roots.add(a)
roots.add(b)
roots.add(c)
n = n - 1
if n == 0:
break
que.append((b, c, k * (b + c) - a))
que.append((a, c, k * (a + c) - b))