Created
November 8, 2019 03:36
-
-
Save wicksome/f1ec29c69d99df12e910e532f6b82cbe to your computer and use it in GitHub Desktop.
Get gcd, lcm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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