Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

Algorithm/Baekjoon

[๋ฐฑ์ค€] (Swift) 11653๋ฒˆ - ์†Œ์ธ์ˆ˜๋ถ„ํ•ด

๊ฐ์ž ๐Ÿฅ” 2022. 2. 28. 23:39
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ ๋งํฌ

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

 

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

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

www.acmicpc.net

 

๋‚ด๊ฐ€ ํ‘ผ ํ’€์ด

  • 2๋ถ€ํ„ฐ ์ฐจ๊ทผ์ฐจ๊ทผ ๋‚˜๋ˆ ์ฃผ๋ฉด์„œ print ํ•ด์คŒ
  • ๋ฒ”์œ„๋Š” ์ˆซ์ž num๊นŒ์ง€๋กœ ์„ค์ •ํ–ˆ์Œ
  • ๋งˆ์ง€๋ง‰์— 1์ด ์•„๋‹Œ๊ฒฝ์šฐ ์†Œ์ˆ˜๋กœ ๋งˆ๋ฌด๋ฆฌ ์ง€์–ด์กŒ๋‹ค๋Š” ๋œป์ด๋ฏ€๋กœ, ๋งˆ์ง€๋ง‰ ์†Œ์ˆ˜๋„ ์ถœ๋ ฅํ•ด์คŒ.
  • ๊ตณ์ด ์ •๋ ฌ์€ ํ•„์š”์—†์Œ. 2๋ถ€ํ„ฐ ์‹œ์ž‘ํ•ด์„œ ๊ฐ€์žฅ ์ž‘์€ ์†Œ์ˆ˜๋ถ€ํ„ฐ ์ถœ๋ ฅ๋˜๊ฒŒ ๋จ
import Foundation

var num = Int(readLine()!)!
let n = Int(sqrt(Double(num)))

for i in stride(from: 2, to: num, by: 1) {
    while num % i == 0 {
        num /= i
        print(i)
    }
}


if num != 1 {
    print(num)
}

 

๋ฐ˜์‘ํ˜•