Algorithms
[λ°±μ€] 4948λ²: λ² λ₯΄νΈλ 곡μ€
thals0
2022. 7. 30. 14:23
728x90
https://www.acmicpc.net/problem/4948
4948λ²: λ² λ₯΄νΈλ 곡μ€
λ² λ₯΄νΈλ 곡μ€μ μμμ μμ°μ nμ λνμ¬, nλ³΄λ€ ν¬κ³ , 2nλ³΄λ€ μκ±°λ κ°μ μμλ μ μ΄λ νλ μ‘΄μ¬νλ€λ λ΄μ©μ λ΄κ³ μλ€. μ΄ λͺ μ λ μ‘°μ ν λ² λ₯΄νΈλμ΄ 1845λ μ μΆμΈ‘νκ³ , ννλν° μ²΄λΉμΌ
www.acmicpc.net
μ²μ μ½λ:
while(1):
a=int(input())
if a ==0:
break
cnt=0
for i in range(a+1,2*a+1):
if i == 1:
continue
for j in range(2,int(i**0.5)+1):
if i % j == 0:
break
else:
cnt+=1
print(cnt)
κ° ν
μ€νΈ μΌμ΄μ€λ§λ€ κ³μ μμλ₯Ό κ³μ°νλκΉ μκ° μ΄κ³Ό λ°μ
μ λ΅ μ½λ:
sosu =[]
for i in range(2,246913):
cnt = 0
for j in range(2, int(i**0.5)+1):
if i % j ==0:
cnt += 1
break
if cnt == 0:
sosu.append(i)
while(1):
a = int(input())
count = 0
if a == 0:
break
for i in sosu:
if a < i <= 2*a:
count +=1
print(count)
λ¬Έμ μμ μ£Όμ΄μ§ λ²μ λ΄μμ μμλ₯Ό λ¨Όμ λͺ¨λ ꡬνκ³ μμνλ λ°©λ²μΌλ‘ μκ° μ΄κ³Ό ν΄κ²°
728x90