Python 기본 사항쉬움

최고공약수(HCF)

'최고 공통 인자(HCF)' 문제에 대한 자세한 가이드 및 Python 구현입니다.

문제 설명

쉬움

두 개의 양의 정수 ab을 사용하여 최고 공통 인자(HCF)를 반환하는 함수 find_hcf(a, b)을 작성하세요. HCF는 나머지를 남기지 않고 두 숫자를 나누는 가장 큰 양의 정수입니다.

예를 들어, 12와 18의 HCF는 6입니다. 6은 12와 18을 균등하게 나누는 가장 큰 숫자이기 때문입니다.

제약
  • 1 <= a, b <= 10^6

Example 1
Input
find_hcf(12, 18)
Output
6
Explanation

Factors of 12: 1, 2, 3, 4, 6, 12. Factors of 18: 1, 2, 3, 6, 9, 18. Common factors: 1, 2, 3, 6. Highest is 6.

Example 2
Input
find_hcf(24, 36)
Output
12
Explanation

Factors of 24: 1, 2, 3, 4, 6, 8, 12, 24. Factors of 36: 1, 2, 3, 4, 6, 9, 12, 18, 36. Highest common factor is 12.

Example 3
Input
find_hcf(7, 13)
Output
1
Explanation

7 and 13 are both prime numbers with no common factors other than 1.

Need a Hint?
세트나 힙과 같은 Numbers 관련 데이터 구조를 사용해 보세요.
Edge Cases to Watch
  • 빈 입력 구조
  • 단일 요소 입력
  • 큰 수치 범위

해결할 준비가 되셨나요?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

편집기에서 열기
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.