물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Count the divisors of a number

BEstyle 2022. 9. 30. 18:45

DESCRIPTION:

Count the number of divisors of a positive integer n.

Random tests go up to n = 500000.

Examples (input --> output)

4 --> 3 (1, 2, 4)
5 --> 2 (1, 5)
12 --> 6 (1, 2, 3, 4, 6, 12)
30 --> 8 (1, 2, 3, 5, 6, 10, 15, 30)

def divisors(n):
    if n==1:
        return 1
    count=0
    for i in range(2,n):
        if n/i ==int(n/i):
            count+=1
    return count+2

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Array.diff  (0) 2022.10.04
Remove the minimum  (0) 2022.09.30
Range Bit Counting  (0) 2022.09.30
Ascend, Descend, Repeat?  (0) 2022.09.29
Find the missing letter  (1) 2022.09.29