Skip to content

Instantly share code, notes, and snippets.

@wicksome
Created November 8, 2019 03:36
Show Gist options
  • Save wicksome/f1ec29c69d99df12e910e532f6b82cbe to your computer and use it in GitHub Desktop.
Save wicksome/f1ec29c69d99df12e910e532f6b82cbe to your computer and use it in GitHub Desktop.
Get gcd, lcm
publi class Solution {
public int[] solution(int n, int m) {
int[] answer = {gcd(n, m), lcm(n, m)};
return answer;
}
private int gcd(int a, int b) { // 최대공약수
while (b > 0) {
int tmp = a;
a = b;
b = tmp % b;
}
return a;
}
private int lcm(int a, int b) { // 최소공배수
return a * b / gcd(a, b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment