def gcd(a, b):
while b:
a, b = b, a % b
return a
def main(a,b,c):
return(gcd(gcd(a,b),c))
def getPowers(n, p):
vac=[]
with open(str(p)+".txt", "r") as f:
for x in range(1, n + 1):
vac.append(f.readline(x))
return vac
def detNumbers(n,p):
xxx=0
a1=[]
a2=[]
a3=[]
vac=getPowers(n, p)
for x in range(1, p):
for y in range(x + 1, p-1):
for z in range(y+1, p+1):
if main(x,y,z)==1:
if gcd(x, y)==gcd(y, z)==gcd(x, z)==1:
if vac[x]+vac[y]==vac[z]:
xxx=xxx+1
a1[xxx].append(x)
a2[xxx].append(y)
a3[xxx].append(z)
for c in range(1, p+1):
with open("Тройки"+str(c)+".txt", "w") as f:
for g in range(1, xxx + 1):
f.write(a1[g] + " " + a2[g] + " " + a3[g] + "\n")
for pop in range(1, 1000+1):
detNumbers(2000,pop)