Skip to content

Instantly share code, notes, and snippets.

@shaobin0604
Created March 17, 2010 16:07
Show Gist options
  • Select an option

  • Save shaobin0604/335393 to your computer and use it in GitHub Desktop.

Select an option

Save shaobin0604/335393 to your computer and use it in GitHub Desktop.
最大公约数
public class Test {
public static void main(String[] args) {
int a = 165, b = 55;
System.out.printf("%d 和 %d 的最大公约数是: %d\n", a, b, gcd(a, b));
}
public static int gcd(int a, int b) {
// suppose a > b;
int r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment