이 기사에서는 주어진 문제 설명을 해결하기 위한 솔루션과 접근 방식에 대해 알아볼 것입니다.
문제 설명 −수 "n"이 주어졌을 때, 약수의 총 수가 짝수 또는 홀수인지 확인합니다.
이 접근 방식에서는 모든 제수를 찾고 제수의 개수가 짝수인지 홀수인지 확인합니다.
구현은 다음과 같습니다 -
예시
import math
def countDivisors(n) :
count = 0
# calculating all the divisors
root=int(math.sqrt(n))+2
for i in range(1, root) :
if (n % i == 0) :
# If divisors are equal,increment count by one Otherwise increment count by 2
if( n // i == i) :
count = count + 1
else :
count = count + 2
if (count % 2 == 0) : def countDivisors(n) :
count = 0
# calculating all the divisors
root=int(math.sqrt(n))+2
for i in range(1, root) :
if (n % i == 0) :
# If divisors are equal,increment count by one Otherwise increment count by 2
if( n // i == i) :
count = count + 1
else :
count = count + 2
if (count % 2 == 0) :
print("Even")
else :
print("Odd")
# Driver program to test above function */
print("The count of divisor: ")
countDivisors(100)
print("Even")
else :
print("Odd")
# Driver program to test above function */
print("The count of divisor: ")
countDivisors(100) 출력
120 No
모든 변수는 아래 이미지와 같이 전역 범위에서 선언됩니다.

결론
이 기사에서는 제수의 개수가 주어진 숫자의 짝수인지 홀수인지 확인하는 접근 방식에 대해 배웠습니다.