嗨,我一直在试图解决这个问题,并且需要一些有关如何开始的帮助。我应该写一个脚本来计算给定n值的解数(x,y)。我将其范围缩小到x,y必须大于n,并且每当n为质数时,只有两个解。每n个解决方案之一是(2n,2n)。有谁知道如何编写脚本来查找所有解决方案?谢谢,非常感谢
以下代码可能会有所帮助
res = cell(); % create empty cell to save solutions
for x = 1:5000
for y = x:5000 % y starts from x till 5000, to avoid duplicated solutions
if mod(x*y,x+y)==0 % if x*y is divisible by (x+y), then n as a integer exists, so save such [x,y] to the cell array res
res{end+1} = {[x,y]};
end
end
end