Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

37-Dolchae #141

Merged
merged 1 commit into from
Mar 22, 2024
Merged

37-Dolchae #141

merged 1 commit into from
Mar 22, 2024

Conversation

Dolchae
Copy link
Collaborator

@Dolchae Dolchae commented Mar 19, 2024

๐Ÿ”— ๋ฌธ์ œ ๋งํฌ

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

โœ”๏ธ ์†Œ์š”๋œ ์‹œ๊ฐ„

15๋ถ„

โœจ ์ˆ˜๋„ ์ฝ”๋“œ

๋ฌธ์ œ

ํ•˜๋‚˜์˜ ์ •์ˆ˜ N์„ ์ž…๋ ฅ ๋ฐ›๊ณ  ์†Œ์ธ์ˆ˜๋ถ„ํ•ดํ•œ ๊ฒฐ๊ณผ๋ฅผ ์ถœ๋ ฅํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.

์„ค๋ช… + ์ „์ฒด ์ฝ”๋“œ

n = int(input())

for i in range(2, n+1):
    while True:
        if not n%i == 0:
            break
        print(i)
        n /= i

n์„ ์ž…๋ ฅ ๋ฐ›๊ณ  2~n๊นŒ์ง€ for๋ฌธ์„ ์ง„ํ–‰ํ•œ๋‹ค.
n์ด i๋กœ ๋‚˜๋ˆ ์ง€์ง€ ์•Š์„ ๋•Œ๊นŒ์ง€ while๋ฌธ์„ ์ง„ํ–‰ํ•˜๋ฉฐ i(์†Œ์ธ์ˆ˜)๋ฅผ ์ถœ๋ ฅํ•˜๊ณ , n์„ i๋กœ ๋‚˜๋ˆ„์–ด์ค€๋‹ค.

๐Ÿ“š ์ƒˆ๋กญ๊ฒŒ ์•Œ๊ฒŒ๋œ ๋‚ด์šฉ

6๊ฐœ์›” ์ „์— C๋กœ ํ’€์—ˆ๋‹ค๊ฐ€ ์‹œ๊ฐ„์ดˆ๊ณผ ๋‚ฌ๋˜ ๋ฌธ์ œ์ธ๋ฐ ํŒŒ์ด์ฌ์œผ๋กœ ๋‹ค์‹œ ํ’€์–ด๋ณด์•˜๋‹ค. ์˜ค๋Š˜..์€ ์กฐ๊ธˆ ์‰ฌ์–ด๊ฐ€๊ฒ ์Šต๋‹ˆ๋‹ค......๐Ÿฅฒ ์ƒ๋Œ€์ ์œผ๋กœ ์‰ฌ์šด ๋ฌธ์ œ์ธ๋งŒํผ ์‹œ๊ฐ„ ํšจ์œจ์ด ์ค‘์š”ํ•œ ๊ฒƒ ๊ฐ™์€๋ฐ ๋” ์ž˜ํ•˜์‹œ๋Š” ์šฐ๋ฆฌ ํŒ€์› ๋ถ„๋“ค์ด ๋” ์ข‹์€ ์ฝ”๋“œ๋กœ ์˜ฌ๋ ค์ฃผ์‹œ๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”โ˜บ๏ธ๐Ÿ‘

Copy link
Collaborator

@9kyo-hwang 9kyo-hwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ €๋„ ์˜ˆ-์ „์— C ์ฒ˜์Œ ๋ฐฐ์šธ ๋•Œ ์ด๋Ÿฐ ๋ฌธ์ œ ํ’€์—ˆ๋˜ ๊ฒƒ ๊ฐ™์€๋ฐ... ๊ฐ„๋งŒ์— ์†Œ์ธ์ˆ˜๋ถ„ํ•ด ๋‹ค์‹œ ์ฐพ์•„๋ดค๋„ค์š” :p

@@ -0,0 +1,8 @@
n = int(input())

for i in range(2, n+1):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์†Œ์ธ์ˆ˜๋ถ„ํ•ด๋Š” ๊ผญ n๊นŒ์ง€ ๋Œ ํ•„์š”๋Š” ์—†๋‹ต๋‹ˆ๋‹ค :) $\sqrt{n}$๊นŒ์ง€๋งŒ ๋Œ์•„๋„ ์ถฉ๋ถ„ํ•ฉ๋‹ˆ๋‹ค!

for i in range(2, int(n ** 0.5) + 1):
    ...

Comment on lines +4 to +8
while True:
if not n%i == 0:
break
print(i)
n /= i
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ฐ˜๋ณต - ์ค‘๋‹จ ์กฐ๊ฑด์„ ๋’ค์ง‘๋Š” ๊ฒŒ ์กฐ๊ธˆ ๋” ์ง๊ด€์ ์ผ ๊ฒƒ ๊ฐ™๋„ค์š”

while n % i == 0:
    print(i)
    n //= i

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด๋ ‡๊ฒŒ ํ•ด์ฃผ๊ณ  ๋งˆ์ง€๋ง‰์— ํ•œ ๋ฒˆ๋งŒ ๋” ๊ฒ€์‚ฌํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

if n > 1:
    print(n)

Copy link
Member

@xxubin04 xxubin04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ž˜ ํ•˜์…”์„œ ์ œ ์ฝ”๋“œ๋งŒ ๋‚จ๊ธฐ๊ณ  ๊ฐ€๊ฒ ์Šต๋‹ˆ๋‹ค!
while๋ฌธ์ด ์ด์ค‘์œผ๋กœ ์“ฐ์—ฌ์„œ ํšจ์œจ์ ์ธ ์ฝ”๋“œ๋Š” ์•„๋‹Œ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค..

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

Copy link
Member

@gjsk132 gjsk132 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ถ„๋ฅ˜๊ฐ€ ์ •์ˆ˜๋ก ์ด๊ธธ๋ž˜ ์†Œ์ธ์ˆ˜๋ถ„ํ•ด๋ฅผ ๋ญ”๊ฐ€ ํšจ์œจ์ ์œผ๋กœ ํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์„๊นŒ ์‹ถ์–ด์„œ ์•ฝ๊ฐ„ ์ฐ๋จนํ–ˆ๋Š”๋ฐ... ์ง€๊ธˆ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ๋ฐฉ์‹์ด ๊ธฐ์ดˆ์ ์ธ ๋ฐฉ์‹์ด๊ณ ...
๊ทธ ๋‹ค์Œ์œผ๋กœ๋Š” ํŽ˜๋ฅด๋งˆ? ํด๋ผ๋“œ ๋กœ?? ์ด์ฐจ?????
๋จธ๋ฆฟ์†์— ๋‚จ์€ ๊ฑด ????? ๋ฐ–์— ์—†๋„ค์š”...

์ œ ์ƒ๊ฐ์—” ๊ธฐ์ดˆ๊นŒ์ง€๊ฐ€ ๋ชจ๋‘(์ฝ”๋“œ ๋Œ๋ฆฌ๋Š” ์ปดํ“จํ„ฐ ์ œ์™ธ)๊ฐ€ ํ–‰๋ณตํ•œ ์ฝ”๋“œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ^^

n=int(input())

for i in range(2,int(n**(0.5))+1):
    while n%i==0:
        print(i)
        n//=i
    
if n!=1:
    print(n)

๋งˆ์ง€๋ง‰ ์กฐ๊ฑด๋ฌธ์€ n์ด 1์ด ์•„๋‹ˆ๋ผ๋ฉด int(n ** 0.5) + 1๋ณด๋‹ค ํฐ ์†Œ์ˆ˜์ด๊ธฐ ๋•Œ๋ฌธ์— ์ถœ๋ ฅํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants