본문 바로가기
Algorithm

[수학/브루트포스] 백준 14782 Bedtime Reading, I - 파이썬(Python)

by jangThang 2022. 12. 26.
반응형

백준 온라인 저지

 

[ Contents ]

     

     

    1. 문제 (링크 참조)

     

    14782번: Bedtime Reading, I

    Farmer John was performing his nightly bedtime reading duties for Bessie. "Oh, this gives me a headache," moaned Bessie. "But it's just simple number theory," replied FJ. "Let's go over it again. The sigma function of a number is just the sum of the diviso

    www.acmicpc.net

     

     

     

    2. 문제 풀이

     n의 약수의 개수를 찾는 문제입니다.

     

     

     

    3. 코드

    n = int(input())
    res = 0
    for i in range(1, n+1):
        if n % i == 0:
            res += i
    print(res)

     1부터 n까지 브루트포스 방식으로 약수가 있는지 찾아줍니다. 물론 이것보다 더 효율적인 방법이 있으나, 해당 방식을 쓰지 않아도 통과됩니다.

    https://star7sss.tistory.com/574 (더 효율적인 방식)

     

    star가 되고나서 Tistory

    반응형

    댓글