Skip to content

Instantly share code, notes, and snippets.

@pzp1997
Created February 24, 2020 14:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pzp1997/535185f61983a4dc323f7a8c2d222ad3 to your computer and use it in GitHub Desktop.
Save pzp1997/535185f61983a4dc323f7a8c2d222ad3 to your computer and use it in GitHub Desktop.
public class EuclidAglo {
// cd(x, y, z) <==> (x % z == 0) && (y % z == 0)
// gcd(x, y, z) <==> cd(x, y, z) && (\forall int k;; cd(x, y, k) ==> k <= z)
//@ requires true;
//@ ensures (x % \result == 0) && (y % \result == 0) && (\forall int k;; (x % k == 0) && (y % k == 0) ==> k <= \result);
public static int run(int x, int y) {
int n = x;
int m = y;
//@ maintaining (\forall int z;; ((x % z == 0) && (y % z == 0) && (\forall int k;; (x % k == 0) && (y % k == 0) ==> k <= z)) <==> ((n % z == 0) && (m % z == 0) && (\forall int k;; (n % k == 0) && (m % k == 0) ==> k <= z)));
//@ decreases n;
while (n != m) {
if (n > m) {
n -= m;
} else {
m -= n;
}
}
return n;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment