์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ฌธ์ œ/BOJ_Python

[BOJ/Step9] 11653 : ์†Œ์ธ์ˆ˜๋ถ„ํ•ด (Python)

NaNaRin๐Ÿ™ƒ 2021. 2. 14. 17:08

www.acmicpc.net/problem/11653

 

11653๋ฒˆ: ์†Œ์ธ์ˆ˜๋ถ„ํ•ด

์ฒซ์งธ ์ค„์— ์ •์ˆ˜ N (1 ≤ N ≤ 10,000,000)์ด ์ฃผ์–ด์ง„๋‹ค.

www.acmicpc.net


๋ฌธ์ œ

์ •์ˆ˜ N์ด ์ฃผ์–ด์กŒ์„ ๋•Œ, ์†Œ์ธ์ˆ˜๋ถ„ํ•ดํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

 

์ž…๋ ฅ

์ฒซ์งธ ์ค„์— ์ •์ˆ˜ N (1 ≤ N ≤ 10,000,000)์ด ์ฃผ์–ด์ง„๋‹ค.

 

์ถœ๋ ฅ

N์˜ ์†Œ์ธ์ˆ˜๋ถ„ํ•ด ๊ฒฐ๊ณผ๋ฅผ ํ•œ ์ค„์— ํ•˜๋‚˜์”ฉ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ถœ๋ ฅํ•œ๋‹ค. N์ด 1์ธ ๊ฒฝ์šฐ ์•„๋ฌด๊ฒƒ๋„ ์ถœ๋ ฅํ•˜์ง€ ์•Š๋Š”๋‹ค.

 

์˜ˆ์ œ ์ž…๋ ฅ 1

72

 

์˜ˆ์ œ ์ถœ๋ ฅ 1

2

2

2

3

3

 

์˜ˆ์ œ ์ž…๋ ฅ 2

3

 

์˜ˆ์ œ ์ถœ๋ ฅ 2

3

 

์˜ˆ์ œ ์ž…๋ ฅ 3

6

 

์˜ˆ์ œ ์ถœ๋ ฅ 3

2

3

 

์˜ˆ์ œ ์ž…๋ ฅ 4

2

 

์˜ˆ์ œ ์ถœ๋ ฅ 4

2

 

์˜ˆ์ œ ์ž…๋ ฅ 5

9991

 

์˜ˆ์ œ ์ถœ๋ ฅ 5

97

103


ํ’€์ด

1. i ์— 2๋ฅผ ์ €์žฅ

2. ์ž…๋ ฅ๋ฐ›์€ n์„ i๋กœ ๋‚˜๋ˆˆ๋‹ค

  2-1. ๋‚˜๋จธ์ง€๊ฐ€ 0์ด๋ฉด i๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  n์„ i๋กœ ๋‚˜๋ˆ  n์— ์ €์žฅ

  2-2. ๋‚˜๋จธ์ง€๊ฐ€ 0์ด ์•„๋‹ˆ๋ฉด i๋ฅผ 1 ์ฆ๊ฐ€

  2-3. n์ด 1์ด ๋˜๋ฉด while๋ฌธ ํƒˆ์ถœ

# 11653.py

n = int(input())
i = 2
while n != 1:
    if n % i == 0:
        print(i)
        n /= i
    else:
        i += 1

( ๋ฉ”๋ชจ๋ฆฌ๋„ ์—„์ฒญ ์“ฐ๊ณ  ์‹œ๊ฐ„์€ ์™œ์ด๋ฆฌ ๋งŽ์ด ๊ฑธ๋ฆฌ๋Š”๊ฑฐ์ง€..)