본문 바로가기
C++

[프로그래머스] 공배수

by 띰쥬 2025. 8. 27.
728x90
반응형
SMALL

#include <string>
#include <vector>

using namespace std;

int solution(int number, int n, int m) {
    int val1 = number%n > 0 ? 0:1;
    int val2 = number%m > 0 ? 0:1;
    
    if(val1*val2)
        return 1;
    else
        return 0;
}

 

 

 

#include <string>
#include <vector>

using namespace std;

int solution(int number, int n, int m) {
    return (number%n==0) && (number%m==0)? 1: 0;
}

 

 

* &&연산을 활용해서 한줄로 작성가능

728x90
반응형
LIST

댓글