321
社区成员




勾股数是一组三个正整数,它们可以作为直角三角形的三条边。 比如3 4 5就是一组勾股数。 如果给出一组勾股数其中的两个,你能找出余下的一个吗?
第一行输入两个整数n。(1<=n<=1000000)表示一组勾股数其中的两个。
如果余下的一个勾股数存在,则输出之。 如果不存在,则输出-1。
没什么算法,就是看有没有对应的整数数字
a,b = map(int,input().split())
c1,c2 = (a ** 2 + b ** 2) ** .5,(max(a,b) ** 2 - min(a,b) ** 2) ** .5
if c1 > 0 and c1 == int(c1):print(int(c1))
elif c2 > 0 and c2 == int(c2):print(int(c2))
else:print(-1)
a = readline().split(' ').map(x => parseInt(x)).sort((x,y) => x > y ? -1 : 1)
var c1 = (a[0] ** 2 + a[1] ** 2) ** .5,c2 = (a[0] ** 2 - a[1] ** 2) ** .5
if (c1 > 0 && parseInt(c1) == c1){print(c1)}
else if (c2 > 0 && parseInt(c2) == c2){print(c2)}
else{print(-1)}