Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我如何将下一个有理数生成为 2 个整数变量。例如,如果我有 x=3 且 y = 2,则下一个有理数是 x=3 且 y=3。数字生成需要像下一个顺序:
查看所需订单
有人知道我该如何实现它?谢谢
n 是分子,d 是分母:
if (n%2 == d%2) { n++; if (d > 1) d--; } else { d++; if (n > 1) n--; }