#644함수로 prime/composite 판별하기
기초
⏱ 시간 제한: 5초|💾 메모리 제한: 128 MB
문제 설명
1보다 큰 자연수 1개를 입력 받아 소수인 경우 prime, 합성수인 경우 composite를 출력하세요.
단, 함수형 문제이므로 함수 prime()만 제출하시오.
참고 int 형 정수 값 1개를 전달 받아 prime/composite 를 구분해 출력할 수 있도록 하는 bool 형 함수 prime()은 다음과 같이 설계할 수 있습니다.
bool prime(int k) {int i; for(i=2; i
미리 작성된 코드
아래 코드에서 주석 위치에 함수를 작성하여 제출하세요.
C 언어
c
#include
int n;
/* 여기에 함수를 작성하세요 */
int main()
{scanf("%d", &n);
if(prime(n)) printf("prime");
else printf("composite");
return 0;}Python
python
# 여기에 함수를 작성하세요
n = int(input())
if prime(n): print('prime', end='')
else: print('composite', end='')입력 설명
int 형 정수(n)가 입력된다. (2 <= n <= 1000000)
출력 설명
소수인 경우 prime, 합성수인 경우 composite 를 출력합니다.
예제
입력 1
2
출력 1
prime
입력 2
4
출력 2
composite