-
6782. 현주가 좋아하는 제곱근 놀이카테고리 없음 2019. 3. 5. 18:2712345678910111213141516171819202122232425import mathfor t in range(int(input())):n = int(input())cnt = 0while True:if n == 2:break#n이 1일때 처리를 안해주면 무한루프를 돈다.if n == 1:cnt += 1break#n보다 작거나 같은 최대의 제곱수를 구한다. ex) 8 -> 2tmp = int(math.sqrt(n))if pow(tmp,2) == n: #n이 제곱수cnt += 1n = int(math.sqrt(n))else:cnt += (pow(tmp+1,2)-n) #n보다 큰 최소의 제곱수에서 n을 빼서 횟수에 추가cnt += 1 #제곱근 구하는 횟수 추가n = int(math.sqrt(n))+1print(f'#{t+1} {cnt}')
cs ㅇ입력값, 출력값