[Programmers] #181936 - 공배수 [Java][C++][Python]
[Programmers] #181936 - 공배수 [Java][C++][Python]
1. 아이디어
number가 $n$으로도 $m$으로도 나누어떨어지면 공배수이므로, 두 나머지가 모두 0인지만 확인하면 된다.
2. 코드
풀이 [Java][C++][Python]
1
2
3
4
5
class Solution {
public int solution(int number, int n, int m) {
return number % n == 0 && number % m == 0 ? 1 : 0;
}
}
1
2
3
4
5
6
#include <bits/stdc++.h>
using namespace std;
int solution(int number, int n, int m) {
return number % n == 0 && number % m == 0;
}
1
2
def solution(number, n, m):
return int(number % n == 0 and number % m == 0)
This post is licensed under CC BY 4.0 by the author.