Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Archives
Today
Total
관리 메뉴

RUBY

소인수, 소인수분해(파이썬 출력) 본문

프로그래밍 언어/Python

소인수, 소인수분해(파이썬 출력)

ruby-jieun 2023. 1. 17. 18:18

 

 

소인수와 소인수분해


 

 

 

100부터 1000사이의 난수를 소인수분해 하고 각각의 소인수에 대한 지수를 출력

import random

rNum = random.randint(100, 1000)
print(f'rNum: {rNum}')

soinsuList = []

n = 2
while n <= rNum:
    if rNum % n == 0:
        print(f'소인수: {n}')
        soinsuList.append(n)
        rNum /= n
    else:
        n += 1

print(f'soinsuList: {soinsuList}')

tempNum = 0
for s in soinsuList:
    if tempNum != s:
        print(f'{s}\'s count: {soinsuList.count(s)}')
        tempNum = s

'프로그래밍 언어 > Python' 카테고리의 다른 글

최소공배수(파이썬 출력)  (0) 2023.01.18
최대공약수(파이썬 출력)  (0) 2023.01.18
약수,소수,소인수(파이썬 출력)  (0) 2023.01.17
확률(파이썬 출력)  (0) 2023.01.17
조합(파이썬 출력)  (0) 2023.01.16
Comments