最大公约数 - 前后条件

时间:2012-12-29 13:40:09

标签: java uml preconditions post-conditions

以下提供了gcd方法的前后条件。

pre: x > 0 & y > 0 
post: result > 0 &
      x mod result = 0 & y mod result = 0 &
      ∀t:Integer · t > 0 & x mod t = 0 & y mod t = 0 ⇒ result mod t = 0

然而,我在跟踪帖子条件时遇到了麻烦...对我来说它基本上说找到任何可被两者整除的整数。它如何得到最大除数,实际上说的条件是什么?

1 个答案:

答案 0 :(得分:4)

这一点确保result是所有常见除数中最大的。

∀t:Integer·t>0 & x mod t=0 & y mod t = 0 ⇒ result mod t = 0

它表示任何txy的公约数,也是result

的除数

编辑:您应该阅读以上这一行:

∀t:Integer·((t>0 & x mod t=0 & y mod t = 0) ⇒ result mod t = 0)