본문 바로가기

Algorithm/Implementation

(Python3) - 백준(BOJ) 14782 : Bedtime Reading, I

반응형

https://www.acmicpc.net/problem/14782

 

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

간단 구현 문제였습니다.

📕 풀이방법

📔 입력 및 초기화

n, 정답 ans를 선언 후 입력받습니다.

📔 풀이과정

1 ~ n까지 for loop를 수행합니다. 약수라면 ans에 약수를 더해줍니다.

📔 정답출력

ans를 출력합니다.


📕 Code

import sys
input = sys.stdin.readline

n = int(input())
ans = 0

for i in range(1,n+1):
  if(n % i == 0):
    ans += i

print(ans)

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.